STL array的max_size方法(14)

原文地址:http://www.cplusplus.com/reference/array/array/max_size/
public member function
<array>

std::array::max_size

constexpr size_type max_size() noexcept;
Return maximum size
Returns the maximum number of elements that the array container can hold.

返回array容器所能存放的元素的最大数目。


The max_size of an array object, just like its size, is always equal to the second template parameter used to instantiate the array template class.

对于array的max_size,和size一样大一般都是等于实例化时的第二个模版参数。(和vector的很不一样

例子:

#include <iostream>
#include <array>
using namespace std;
int main(){
	array<int,5> ai;
	cout<<"ai.size="<<ai.size()<<endl;
	cout<<"ai.max_size="<<ai.max_size()<<endl;


}
运行截图:



Parameters

none

Return Value

The maximum number of elements the object can hold as content.

This is a constexpr.

返回array所能存放元素的最大数目,

这是一个常量。


Member type size_type is an alias of the unsigned integral type size_t.

Example

1
2
3
4
5
6
7
8
9
10
11
12
// array::max_size
#include <iostream>
#include <array>

int main ()
{
  std::array<int,10> myints;
  std::cout << "size of myints: " << myints.size() << '\n';
  std::cout << "max_size of myints: " << myints.max_size() << '\n';

  return 0;
}


Output:
size of myints: 10
max_size of myints: 10
size and max_size of an array object always match.

array的size和max_size一般都是相等的。


Complexity

Constant.

Iterator validity

No changes.

Data races

The container is accessed.
No contained elements are accessed: concurrently accessing or modifying them is safe.

容器将被访问。

容器内的元素不会被访问,同时访问以及修改他们都是安全的。

Exception safety

No-throw guarantee: this member function never throws exceptions.

该方法不会抛出异常。



——————————————————————————————————————————————————————————————————

//总结的不好的地方请多多指导,可以在下面留言或者点击左上方邮件地址给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。

转载请注明出处:http://blog.csdn.net/qq844352155
author:天下无双

Email:coderguang@gmail.com

2014-8-30

于GDUT

——————————————————————————————————————————————————————————————————









  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值