std::flat_map<Key,T,Compare,KeyContainer,MappedContainer>::empty

出自cppreference.com
< cpp‎ | container‎ | flat map
 
 
 
 
bool empty() const noexcept;
(C++23 起)

檢查底層容器是否為空,即是否 c.empty()

檢查底層各容器是否沒有元素。等價於:return begin() == end();

目錄

[編輯] 參數

(無)

[編輯] 返回值

若底層各容器為空則為 true,否則為 false

[編輯] 複雜度

常數。

[編輯] 示例

下列代碼用 empty 檢查 std::flat_map<int, int> 是否含有任何元素:

#include <iostream>
#include <flat_map>
#include <utility>
 
int main()
{
    std::flat_map<int,int> numbers;
    std::cout << std::boolalpha;
    std::cout << "起初, numbers.empty(): " << numbers.empty() << '\n';
 
    numbers.emplace(42, 13);
    numbers.insert(std::make_pair(13317, 123));
    std::cout << "添加元素后, numbers.empty(): " << numbers.empty() << '\n';
}

輸出:

起初, numbers.empty(): true
添加元素后, numbers.empty(): false

[編輯] 參閱

返回元素數
(公開成員函數) [編輯]
(C++17)
檢查容器是否為空
(函數模板) [編輯]