std::size
Defined in header <iterator> | | |
---|---|---|
template < class C > constexpr auto size( const C& c ) -> decltype(c.size()); | (1) | (since C++17) |
template < class T, size_t N > constexpr size_t size( const T (&array)N ) noexcept; | (2) | (since C++17) |
返回给定容器的大小。c
或阵列array
...
1%29c.size()
...
2%29N
...
参数
c | - | a container with a size method |
---|---|---|
array | - | an array of arbitrary type |
返回值
…的大小c
或array
...
例外
2%29
noexcept
规格:
noexcept
注记
除了被纳入<iterator>
,,,std::size
如果包括下列任何一个标头,则保证可用:<array>
,,,<deque>
,,,<forward_list>
,,,<list>
,,,<map>
,,,<regex>
,,,<set>
,,,<string>
,,,<unordered_map>
,,,<unordered_set>
,和<vector>
...
可能的实施
第一版
*。
模板<class C>自动大小%28 const C&c%29->解密类型%28 c.大小%28%29%29{返回c.大小%28%29;}
第二版
模板<类T,STD::size[医]tN>std::大小[医]T大小%28 const T%28和数组%29n%29 no({返回N;}除外)
例
二次
#include <iostream>
#include <vector>
#include <iterator>
int main()
{
std::vector<int> v = { 3, 1, 4 };
std::cout << std::size(v) << '\n';
int a[] = { -5, 10, 15 };
std::cout << std::size(a) << '\n';
}
二次
产出:
二次
3
3
二次
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com