GeezerVison is showing cpprefjp.github.io — std::empty - cpprefjp C++日本語リファレンス
最終更新日時:
2026年09月11日 13時06分31秒 (JST)
Akira Takahashi
が更新
履歴
編集
function template
<iterator>
std:: empty (C++17)
namespace std {
template < class C >
constexpr auto
empty ( const C & c )
-> decltype ( c . empty ()); // (1) C++17
template < class C >
[[ nodiscard ]] constexpr auto
empty ( const C & c )
-> decltype ( c . empty ()); // (1) C++20
template < class C >
constexpr auto
empty ( const C & c )
noexcept ( noexcept ( c . empty ()))
-> decltype ( c . empty ()); // (1) C++26
template < class T , std::size_t N >
constexpr bool
empty ( const T ( & array )[ N ]) noexcept ; // (2) C++17
template < class T , std::size_t N >
[[ nodiscard ]] constexpr bool
empty ( const T ( & array )[ N ]) noexcept ; // (2) C++20
template < class T , std::size_t N >
constexpr bool
empty ( const T ( & array )[ N ]) noexcept ; // (2) C++26
template < class E >
constexpr bool
empty ( initializer_list < E > il ) noexcept ; // (3) C++17、C++26で削除
template < class E >
[[ nodiscard ]] constexpr bool
empty ( initializer_list < E > il ) noexcept ; // (3) C++20、C++26で削除
}
(3)はC++26で削除された。std::initializer_list に、メンバ関数版のempty() が追加されたため、このオーバーフローは不要になった。使い方としてはこれまで通りに使用できる。
概要
コンテナが空かどうかを判定する。
(3) : C++26で削除。汎用オーバーロード(1)を使用すること。
戻り値
(1) : return c.empty();
(2) : return false;
(3) : return il.size() == 0; (C++26で削除)
備考
機能テストマクロ は__cpp_lib_nonmember_container_accessで値は201411
<iterator>ヘッダを読み込む以外では、以下のヘッダが読み込まれている場合に、この関数を使用できる:
例
出力
false
false
true
false
false
バージョン
言語
処理系
参照