map或者size的max_size()结果会发生变化吗?何时发生变化?

myoswin7 2010-04-22 06:18:34
map或者size的max_size()结果会发生变化吗?何时发生变化?

求max_size()的原理
...全文
149 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
myoswin7 2010-05-10
  • 打赏
  • 举报
回复

我的意思是
函数max_size()
存在的意义是什么呢?
dskit 2010-04-29
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 myoswin7 的回复:]
引用 4 楼 dskit 的回复:

引用 3 楼 myoswin7 的回复:
引用 1 楼 dskit 的回复:

size:
Returns the number of elements in the container.
添加,删除元素的时候改变

max_size():
This is the maximum potential size the container c……
[/Quote]


// map::max_size
#include <iostream>
#include <map>
using namespace std;

int main ()
{
int i;
map<int,int> mymap;

if (mymap.max_size()>1000)
{
for (i=0; i<1000; i++) mymap[i]=0;
cout << "The map contains 1000 elements.\n";
}
else cout << "The map could not hold 1000 elements.\n";

return 0;
}



myoswin7 2010-04-23
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 dskit 的回复:]

引用 3 楼 myoswin7 的回复:
引用 1 楼 dskit 的回复:

size:
Returns the number of elements in the container.
添加,删除元素的时候改变

max_size():
This is the maximum potential size the container can reach due to syst……
[/Quote]

那这个函数存在的意义是什么呢?
dskit 2010-04-22
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 myoswin7 的回复:]
引用 1 楼 dskit 的回复:

size:
Returns the number of elements in the container.
添加,删除元素的时候改变

max_size():
This is the maximum potential size the container can reach due to system or library implement……
[/Quote]
是的。
myoswin7 2010-04-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 dskit 的回复:]

size:
Returns the number of elements in the container.
添加,删除元素的时候改变

max_size():
This is the maximum potential size the container can reach due to system or library implementation limitations.
……
[/Quote]

你的意思是说

在特定的系统使用特定的库,max_size()返回的值是不变的。

对吗?
myoswin7 2010-04-22
  • 打赏
  • 举报
回复
不好意思我的题目写错了!

我的题目应该是

map或者set的max_size()结果会发生变化吗?何时发生变化?
dskit 2010-04-22
  • 打赏
  • 举报
回复
size:
Returns the number of elements in the container.
添加,删除元素的时候改变

max_size():
This is the maximum potential size the container can reach due to system or library implementation limitations.
变化取决于系统或库实现的限制

64,687

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧