Difference between revisions of "Template:cpp/container/empty"
From cppreference.com
m (Text replace - "mark c++11 feature" to "mark since c++11") |
m (+inplace_vector.) |
||
(29 intermediate revisions by 11 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}} |
+ | {{#switch:{{#var:cont}} | ||
+ | |array= | ||
+ | {{dcl|since=c++11| | ||
+ | constexpr bool empty() const noexcept; | ||
}} | }} | ||
− | Checks if the container has no elements, i.e. whether {{ | + | |vector= |
+ | {{dcla|anchor=no|noexcept=c++11|constexpr=c++20| | ||
+ | bool empty() const; | ||
+ | }} | ||
+ | |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; | ||
+ | }} | ||
+ | | | ||
+ | {{dcl|since={{cpp/std|{{#var:cont}}}}| | ||
+ | bool empty() const noexcept; | ||
+ | }} | ||
+ | }} | ||
+ | {{dcl end}} | ||
+ | |||
+ | Checks if the container has no elements, i.e. whether {{c|1=begin() == end()}}. | ||
===Parameters=== | ===Parameters=== | ||
Line 10: | Line 33: | ||
===Return value=== | ===Return value=== | ||
− | + | {{c|true}} if the container is empty, {{c|false}} otherwise. | |
− | {{ | + | |
− | + | ||
− | + | ||
− | + | ||
===Complexity=== | ===Complexity=== | ||
− | Constant | + | Constant. |
− | {{# | + | ===Example=== |
− | = | + | {{#switch:{{#var:cont}} |
+ | |set|multiset|unordered_set|unordered_multiset | ||
+ | ={{include|cpp/container/set/example_empty|{{#var:cont}}}} | ||
+ | |map|multimap|unordered_map|unordered_multimap | ||
+ | ={{include|cpp/container/map/example_empty|{{#var:cont}}}} | ||
+ | |{{include|cpp/container/{{#var:cont}}/example_empty}} | ||
+ | }} | ||
− | {{ | + | ===See also=== |
− | {{ | + | {{dsc begin}} |
− | {{ | + | {{#switch:{{#var:cont}} |
+ | |forward_list= | ||
+ | {{dsc inc|cpp/iterator/dsc distance}} | ||
+ | | | ||
+ | {{dsc inc|cpp/container/dsc size|{{#var:cont}}}} | ||
+ | {{dsc inc|cpp/iterator/dsc empty}} | ||
}} | }} | ||
+ | {{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) |