Namespaces
Variants
Views
Actions

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

From cppreference.com
m (fmt)
m (+flat_(+) adaptors, examples adjustment: WIP.)
Line 2: Line 2:
 
{{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;
Line 14: 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 34: Line 39:
  
 
===Example===
 
===Example===
{{include|cpp/container/{{{1|}}}/example_size}}
+
{{#switch:{{{1|}}}
 +
|set|multiset|unordered_set|unordered_multiset|flat_set|flat_multiset
 +
={{include|cpp/container/set/example size|{{{1|}}}}}
 +
|map|multimap|unordered_map|unordered_multimap|flat_map|flat_multimap
 +
={{include|cpp/container/map/example size|{{{1|}}}}}
 +
|{{include|cpp/container/{{{1|}}}/example size}}
 +
}}
  
 
===See also===
 
===See also===

Revision as of 20:29, 25 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]