Difference between revisions of "Template:cpp/container/empty"
From cppreference.com
m (+inplace_vector.) |
|||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | {{ | + | {{#vardefine:cont|{{{1|}}}}}<!-- |
− | {{cpp/container/{{ | + | -->{{cpp/container/{{#var:cont}}/title|empty}} |
+ | {{cpp/container/{{#var:cont}}/navbar}} | ||
{{dcl begin}} | {{dcl begin}} | ||
− | {{#switch:{{ | + | {{#switch:{{#var:cont}} |
|array= | |array= | ||
− | {{dcl | + | {{dcl|since=c++11| |
constexpr bool empty() const noexcept; | constexpr bool empty() const noexcept; | ||
− | |||
− | |||
}} | }} | ||
|vector= | |vector= | ||
− | {{ | + | {{dcla|anchor=no|noexcept=c++11|constexpr=c++20| |
bool empty() const; | bool empty() const; | ||
− | |||
− | |||
− | |||
− | |||
}} | }} | ||
− | |list|deque|set|map|multiset|multimap | + | |inplace_vector= |
− | {{ | + | {{dcl|anchor=no|since=c++26| |
+ | constexpr bool empty() const noexcept; | ||
+ | }} | ||
+ | |list|deque|set|map|multiset|multimap= | ||
+ | {{dcla|anchor=no|noexcept=c++11| | ||
bool empty() const; | bool empty() const; | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
}} | }} | ||
| | | | ||
− | {{dcl | + | {{dcl|since={{cpp/std|{{#var:cont}}}}| |
bool empty() const noexcept; | bool empty() const noexcept; | ||
− | |||
− | |||
}} | }} | ||
}} | }} | ||
Line 50: | Line 39: | ||
===Example=== | ===Example=== | ||
− | {{#switch:{{ | + | {{#switch:{{#var:cont}} |
− | |set|multiset|unordered_set|unordered_multiset | + | |set|multiset|unordered_set|unordered_multiset |
− | ={{include|cpp/container/set/example_empty|{{ | + | ={{include|cpp/container/set/example_empty|{{#var:cont}}}} |
− | |map|multimap|unordered_map|unordered_multimap | + | |map|multimap|unordered_map|unordered_multimap |
− | ={{include|cpp/container/map/example_empty|{{ | + | ={{include|cpp/container/map/example_empty|{{#var:cont}}}} |
− | |{{include|cpp/container/{{ | + | |{{include|cpp/container/{{#var:cont}}/example_empty}} |
}} | }} | ||
===See also=== | ===See also=== | ||
{{dsc begin}} | {{dsc begin}} | ||
− | {{# | + | {{#switch:{{#var:cont}} |
− | + | |forward_list= | |
{{dsc inc|cpp/iterator/dsc distance}} | {{dsc inc|cpp/iterator/dsc distance}} | ||
| | | | ||
− | {{dsc inc|cpp/container/dsc size|{{ | + | {{dsc inc|cpp/container/dsc size|{{#var:cont}}}} |
{{dsc inc|cpp/iterator/dsc empty}} | {{dsc inc|cpp/iterator/dsc empty}} | ||
}} | }} | ||
{{dsc end}} | {{dsc end}} |
Latest revision as of 00:05, 13 August 2024
bool empty() const noexcept; |
(since {std}) | |
Checks if the container has no elements, i.e. whether begin() == end().
Contents |
[edit] Parameters
(none)
[edit] Return value
true if the container is empty, false otherwise.
[edit] Complexity
Constant.
[edit] Example
Templated content. The link is cpp/container/<PP>/example_empty |
[edit] See also
returns the number of elements (public member function of std::{{{1}}} )
| |
(C++17) |
checks whether the container is empty (function template) |