名稱空間
變體
操作

std::flat_set<Key,Compare,KeyContainer>::count

來自 cppreference.com
< cpp‎ | 容器‎ | flat set
 
 
 
 
size_type count( const Key& key ) const;
(1) (C++23 起)
template< class K >
size_type count( const K& x ) const;
(2) (C++23 起)

返回與指定引數“等價”的鍵的元素數量。

1) 返回鍵為 key 的元素數量。由於此容器不允許重複,所以結果為 1 或 0。
2) 返回與值 x 比較等效的鍵的元素數量。此過載僅當限定 id Compare::is_transparent 有效且表示一個型別時才參與過載決議。它允許在不構造 Key 例項的情況下呼叫此函式。

目錄

[編輯] 引數

key - 要計數的元素的鍵值
x - 與鍵比較的備用值

[編輯] 返回值

鍵與 keyx 比較等效的元素數量,對於過載 (1),該數量為 1 或 0。

[編輯] 複雜度

對容器大小呈對數複雜度,加上對找到的元素數量呈線性複雜度。

[編輯] 示例

[編輯] 參閱

查詢具有特定鍵的元素
(public member function) [edit]
返回與特定鍵匹配的元素範圍
(public member function) [edit]