Defined in header <iterator> | ||||
---|---|---|---|---|
| (1) | (since C++17) | ||
| (2) | (since C++17) |
Returns the size of the given container c
or array array
.
1) Returns
c.size()
. 2) Returns
N
.Parameters
c | - | a container with a size method |
array | - | an array of arbitrary type |
Return value
The size of c
or array
.
Exceptions
2)
noexcept
specification: noexcept
Notes
In addition to being included in <iterator>
, std::size
is guaranteed to become available if any of the following headers are included: <array>
, <deque>
, <forward_list>
, <list>
, <map>
, <regex>
, <set>
, <string>
, <unordered_map>
, <unordered_set>
, and <vector>
.
Possible implementation
First version | ||
---|---|---|
| ||
Second version | ||
|
Example
1 2 3 4 5 6 7 8 9 10 11 12 | #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' ; } |
Output:
1 2 | 3 3 |
Please login to continue.