名前空間
変種

std::multimap<Key,T,Compare,Allocator>::empty

提供: cppreference.com
 
 
 
 
<tbody> </tbody> <tbody class="t-dcl-rev "> </tbody><tbody> </tbody>
bool empty() const;
(C++11未満)
bool empty() const noexcept;
(C++11以上)
(C++20未満)
[[nodiscard]] bool empty() const noexcept;
(C++20以上)

コンテナの持っている要素が無い、つまり begin() == end() かどうかを調べます。

引数

(なし)

戻り値

コンテナが空であれば true、そうでなければ false

計算量

一定。

以下のコードは empty を使用して std::multimap<int, int> が空かどうか調べます。

#include <map>
#include <iostream>
#include <utility>
 
int main()
{
    std::multimap<int, int> numbers;
    std::cout << "Initially, numbers.empty(): " << numbers.empty() << '\n';

    numbers.emplace(42, 13);
    numbers.insert(std::make_pair(13317, 123));  
    std::cout << "After adding elements, numbers.empty(): " << numbers.empty() << '\n';
}

出力:

Initially, numbers.empty(): 1
After adding elements, numbers.empty(): 0

関連項目

要素数を返します
(パブリックメンバ関数) [edit]