Namespaces
Variants
Views
Actions

Difference between revisions of "Template:cpp/container/size"

From cppreference.com
m (+flat_(+) adaptors, examples adjustment: WIP.)
m (rm flat_(+) since they use size ad.)
Line 15: Line 15:
 
|since3=c++20|dcl3=
 
|since3=c++20|dcl3=
 
constexpr size_type size() const noexcept;
 
constexpr size_type size() const noexcept;
}}
 
|flat_set|flat_multiset|flat_map|flat_multimap=
 
{{dcl|since=c++23|
 
size_type size() const noexcept;
 
 
}}
 
}}
 
|
 
|
Line 40: Line 36:
 
===Example===
 
===Example===
 
{{#switch:{{{1|}}}
 
{{#switch:{{{1|}}}
|set|multiset|unordered_set|unordered_multiset|flat_set|flat_multiset
+
|set|multiset|unordered_set|unordered_multiset
 
={{include|cpp/container/set/example size|{{{1|}}}}}
 
={{include|cpp/container/set/example size|{{{1|}}}}}
|map|multimap|unordered_map|unordered_multimap|flat_map|flat_multimap
+
|map|multimap|unordered_map|unordered_multimap
 
={{include|cpp/container/map/example size|{{{1|}}}}}
 
={{include|cpp/container/map/example size|{{{1|}}}}}
 
|{{include|cpp/container/{{{1|}}}/example size}}
 
|{{include|cpp/container/{{{1|}}}/example size}}

Revision as of 08:31, 27 December 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

See also

checks whether the container is empty
(public member function of std::{{{1}}}) [edit]
returns the maximum possible number of elements
(public member function of std::{{{1}}}) [edit]
(C++17)(C++20)
returns the size of a container or array
(function template) [edit]