Difference between revisions of "Template:cpp/container/size"
From cppreference.com
m (+ link to std::size, std::ssize) |
Andreas Krug (Talk | contribs) m (fmt) |
||
Line 1: | Line 1: | ||
− | {{cpp/container/{{{1|}}}/title | size}} | + | {{cpp/container/{{{1|}}}/title|size}} |
{{cpp/container/{{{1|}}}/navbar}} | {{cpp/container/{{{1|}}}/navbar}} | ||
{{dcl begin}} | {{dcl begin}} | ||
{{#switch:{{{1|}}}|array= | {{#switch:{{{1|}}}|array= | ||
− | {{dcl | since=c++11 | | + | {{dcl|since=c++11| |
constexpr size_type size() const noexcept; | constexpr size_type size() const noexcept; | ||
}} | }} | ||
|vector= | |vector= | ||
− | {{dcl rev multi | | + | {{dcl rev multi| |
− | | dcl1= | + | |dcl1= |
size_type size() const; | size_type size() const; | ||
− | | since2=c++11 | dcl2= | + | |since2=c++11|dcl2= |
size_type size() const noexcept; | size_type size() const noexcept; | ||
− | | since3=c++20 | dcl3= | + | |since3=c++20|dcl3= |
constexpr size_type size() const noexcept; | constexpr size_type size() const noexcept; | ||
}} | }} | ||
Line 34: | Line 34: | ||
===Example=== | ===Example=== | ||
− | {{include | cpp/container/{{{1|}}}/example_size}} | + | {{include|cpp/container/{{{1|}}}/example_size}} |
===See also=== | ===See also=== | ||
{{dsc begin}} | {{dsc begin}} | ||
− | {{#ifeq: {{{1|}}} | vector | {{dsc inc | cpp/container/dsc capacity |{{{1|}}}}} }} | + | {{#ifeq:{{{1|}}}|vector|{{dsc inc|cpp/container/dsc capacity|{{{1|}}}}}}} |
− | {{dsc inc | cpp/container/dsc empty |{{{1|}}}}} | + | {{dsc inc|cpp/container/dsc empty|{{{1|}}}}} |
− | {{dsc inc | cpp/container/dsc max_size |{{{1|}}}}} | + | {{dsc inc|cpp/container/dsc max_size|{{{1|}}}}} |
− | {{#switch:{{{1|}}} | vector | deque | list | forward_list={{dsc inc | cpp/container/dsc resize |{{{1|}}}}} }} | + | {{#switch:{{{1|}}}|vector|deque|list|forward_list={{dsc inc|cpp/container/dsc resize |{{{1|}}}}}}} |
− | {{dsc inc | cpp/iterator/dsc size}} | + | {{dsc inc|cpp/iterator/dsc size}} |
{{dsc end}} | {{dsc end}} |
Revision as of 02:45, 30 October 2023
size_type size() const noexcept; |
(since {std}) | |
Returns the number of elements in the container, i.e. std::distance(begin(), end()).
Contents |
Parameters
(none)
Return value
The number of elements in the container.
Complexity
Constant.
Example
Templated content. The link is cpp/container/<PP>/example_size |
See also
checks whether the container is empty (public member function of std::{{{1}}} )
| |
returns the maximum possible number of elements (public member function of std::{{{1}}} )
| |
(C++17)(C++20) |
returns the size of a container or array (function template) |