std::empty (3) - Linux Manuals
std::empty: std::empty
NAME
Synopsis
Defined in header <iterator>
template <class C> (since C++17)
constexpr auto empty(const C& c) -> decltype(c.empty()); (until C++20)
template <class C> (since C++20)
[[nodiscard]] constexpr auto empty(const C& c) -> decltype(c.empty());
template <class T, std::size_t N> (since C++17)
constexpr bool empty(const T (&array)[N]) noexcept; (1) (until C++20)
template <class T, std::size_t N> (since C++20)
[[nodiscard]] constexpr bool empty(const T (&array)[N]) noexcept; (2)
template <class E> (since C++17)
constexpr bool empty(std::initializer_list<E> il) noexcept; (3) (until C++20)
template <class E> (since C++20)
[[nodiscard]] constexpr bool empty(std::initializer_list<E> il) noexcept;
Returns whether the given container is empty.
1) returns c.empty()
2) returns false
3) returns il.size() == 0
Parameters
c - a container with an empty method
array - an array of arbitrary type
il - an initializer list
Return value
true if the container doesn't have any element.
Notes
In addition to being included in <iterator>, std::empty is guaranteed to become available if any of the following headers are included: <array>, <deque>, <forward_list>, <list>, <map>, <regex>, <set>
, <span>
(since C++20), <string>, <string_view>, <unordered_map>, <unordered_set>, and <vector>.
Possible implementation
First version
Second version
Third version
Example
// Run this code
Output: