Difference between revisions of "Template:cpp/container/size"
From cppreference.com
Andreas Krug (Talk | contribs) m (fmt) |
m (+inplace_vector.) |
||
(3 intermediate revisions by one user 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}} | {{dcl begin}} | ||
− | {{#switch:{{ | + | {{#switch:{{#var:cont}} |
+ | |array= | ||
{{dcl|since=c++11| | {{dcl|since=c++11| | ||
constexpr size_type size() const noexcept; | constexpr size_type size() const noexcept; | ||
}} | }} | ||
|vector= | |vector= | ||
− | {{dcl | + | {{dcl|notes={{mark noexcept since c++11}}<br>{{mark constexpr since c++20}}| |
− | + | ||
size_type size() const; | size_type size() const; | ||
− | | | + | }} |
− | + | |inplace_vector= | |
− | | | + | {{dcl|since=c++26| |
− | constexpr size_type size() const | + | constexpr size_type size() const; |
}} | }} | ||
| | | | ||
− | {{cpp/container/noexcept dcl|{{ | + | {{cpp/container/noexcept dcl|{{#var:cont}}|dcl= |
size_type size() const | size_type size() const | ||
}} | }} | ||
Line 34: | Line 35: | ||
===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 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) |