Namespaces
Variants
Views
Actions

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

From cppreference.com
m (Example: `map-like` use shared example)
m (+inplace_vector.)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{cpp/container/{{{1|}}}/title|empty}}
+
{{#vardefine:cont|{{{1|}}}}}<!--
{{cpp/container/{{{1|}}}/navbar}}
+
-->{{cpp/container/{{#var:cont}}/title|empty}}
 +
{{cpp/container/{{#var:cont}}/navbar}}
 
{{dcl begin}}
 
{{dcl begin}}
{{#switch:{{{1|}}}
+
{{#switch:{{#var:cont}}
 
|array=
 
|array=
{{dcl rev multi|since1=c++11|dcl1=
+
{{dcl|since=c++11|
 
constexpr bool empty() const noexcept;
 
constexpr bool empty() const noexcept;
|since2=c++20|dcl2=
 
[[nodiscard]] constexpr bool empty() const noexcept;
 
 
}}
 
}}
 
|vector=
 
|vector=
{{dcl rev multi|dcl1=
+
{{dcla|anchor=no|noexcept=c++11|constexpr=c++20|
 
bool empty() const;
 
bool empty() const;
|since2=c++11|dcl2=
 
bool empty() const noexcept;
 
|since3=c++20|dcl3=
 
[[nodiscard]] constexpr bool empty() const noexcept;
 
 
}}
 
}}
|list|deque|set|map|multiset|multimap|stack|queue|priority_queue=
+
|inplace_vector=
{{dcl rev multi|dcl1=
+
{{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;
|since2=c++11|dcl2=
 
bool empty() const noexcept;
 
|since3=c++20|dcl3=
 
[[nodiscard]] bool empty() const noexcept;
 
}}
 
|flat_set|flat_multiset|flat_map|flat_multimap=
 
{{dcl|since=c++23|1=
 
[[nodiscard]] bool empty() const noexcept;
 
 
}}
 
}}
 
|
 
|
{{dcl rev multi|since1={{cpp/std|{{{1|}}}}}|dcl1=
+
{{dcl|since={{cpp/std|{{#var:cont}}}}|
 
bool empty() const noexcept;
 
bool empty() const noexcept;
|since2=c++20|dcl2=
 
[[nodiscard]] bool empty() const noexcept;
 
 
}}
 
}}
 
}}
 
}}
Line 50: Line 39:
  
 
===Example===
 
===Example===
{{#switch:{{{1|}}}
+
{{#switch:{{#var:cont}}
|set|multiset|unordered_set|unordered_multiset|flat_set|flat_multiset
+
|set|multiset|unordered_set|unordered_multiset
={{include|cpp/container/set/example_empty|{{{1|}}}}}
+
={{include|cpp/container/set/example_empty|{{#var:cont}}}}
|map|multimap|unordered_map|unordered_multimap|flat_map|flat_multimap
+
|map|multimap|unordered_map|unordered_multimap
={{include|cpp/container/map/example_empty|{{{1|}}}}}
+
={{include|cpp/container/map/example_empty|{{#var:cont}}}}
|{{include|cpp/container/{{{1|}}}/example_empty}}
+
|{{include|cpp/container/{{#var:cont}}/example_empty}}
 
}}
 
}}
  
 
===See also===
 
===See also===
 
{{dsc begin}}
 
{{dsc begin}}
{{#ifeq:{{{1|}}}|forward_list
+
{{#switch:{{#var:cont}}
|
+
|forward_list=
 
{{dsc inc|cpp/iterator/dsc distance}}
 
{{dsc inc|cpp/iterator/dsc distance}}
 
|
 
|
{{dsc inc|cpp/container/dsc size|{{{1|}}}}}
+
{{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

[edit] See also

returns the number of elements
(public member function of std::{{{1}}}) [edit]
(C++17)
checks whether the container is empty
(function template) [edit]