Difference between revisions of "Template:cpp/container/size"
From cppreference.com
m (Update links.) |
m (+inplace_vector.) |
||
(17 intermediate revisions by 8 users not shown) | |||
Line 1: | Line 1: | ||
− | {{ | + | {{#vardefine:cont|{{{1|inplace_vector}}}}}<!-- |
− | {{cpp/container/{{ | + | -->{{cpp/container/{{#var:cont}}/title|size}} |
− | + | {{cpp/container/{{#var:cont}}/navbar}} | |
− | {{# | + | {{dcl begin}} |
+ | {{#switch:{{#var:cont}} | ||
+ | |array= | ||
+ | {{dcl|since=c++11| | ||
+ | constexpr size_type size() const noexcept; | ||
}} | }} | ||
+ | |vector= | ||
+ | {{dcl|notes={{mark noexcept since c++11}}<br>{{mark constexpr since c++20}}| | ||
+ | size_type size() const; | ||
+ | }} | ||
+ | |inplace_vector= | ||
+ | {{dcl|since=c++26| | ||
+ | constexpr size_type size() const; | ||
+ | }} | ||
+ | | | ||
+ | {{cpp/container/noexcept dcl|{{#var:cont}}|dcl= | ||
+ | size_type size() const | ||
+ | }} | ||
+ | }} | ||
+ | {{dcl end}} | ||
Returns the number of elements in the container, i.e. {{c|std::distance(begin(), end())}}. | Returns the number of elements in the container, i.e. {{c|std::distance(begin(), end())}}. | ||
Line 11: | Line 29: | ||
===Return value=== | ===Return value=== | ||
− | The number of elements in the container | + | The number of elements in the container. |
− | + | ||
− | + | ||
− | + | ||
===Complexity=== | ===Complexity=== | ||
− | + | Constant. | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
===Example=== | ===Example=== | ||
− | {{include | cpp/container/{{{ | + | {{#switch:{{#var:cont}} |
+ | |set|multiset|unordered_set|unordered_multiset | ||
+ | ={{include|cpp/container/set/example size|{{#var:cont}}}} | ||
+ | |map|multimap|unordered_map|unordered_multimap | ||
+ | ={{include|cpp/container/map/example size|{{#var:cont}}}} | ||
+ | |{{include|cpp/container/{{#var:cont}}/example size}} | ||
+ | }} | ||
===See also=== | ===See also=== | ||
{{dsc begin}} | {{dsc begin}} | ||
− | {{# | + | {{#switch:{{#var:cont}}|vector|inplace_vector={{dsc inc|cpp/container/dsc capacity|{{#var:cont}}}}}} |
− | {{dsc inc | cpp/container/dsc empty |{{ | + | {{dsc inc|cpp/container/dsc empty|{{#var:cont}}}} |
− | {{dsc inc | cpp/container/dsc max_size |{{ | + | {{dsc inc|cpp/container/dsc max_size|{{#var:cont}}}} |
− | {{#switch:{{ | + | {{#switch:{{#var:cont}}|vector|inplace_vector|deque|list|forward_list={{dsc inc|cpp/container/dsc resize|{{#var:cont}}}}}} |
+ | {{dsc inc|cpp/iterator/dsc size}} | ||
{{dsc end}} | {{dsc end}} |
Latest revision as of 22:44, 9 August 2024
constexpr size_type size() const; |
(since C++26) | |
Returns the number of elements in the container, i.e. std::distance(begin(), end()).
Contents |
[edit] Parameters
(none)
[edit] Return value
The number of elements in the container.
[edit] Complexity
Constant.
[edit] Example
Run this code
#include <cassert> #include <inplace_vector> int main() { std::inplace_vector<int, 4> nums; assert(nums.size() == 0); nums = {1, 2, 3, 4}; assert(nums.size() == 4); }
[edit] See also
[static] |
returns the number of elements that can be held in currently allocated storage (public static member function of std::inplace_vector<T,N> )
|
checks whether the container is empty (public member function of std::inplace_vector<T,N> )
| |
[static] |
returns the maximum possible number of elements (public static member function of std::inplace_vector<T,N> )
|
changes the number of elements stored (public member function of std::inplace_vector<T,N> )
| |
(C++17)(C++20) |
returns the size of a container or array (function template) |