std::map<Key,T,Compare,Allocator>::contains
來自 cppreference.com
bool contains( const Key& key ) const; |
(1) | (C++20 起) |
template< class K > bool contains( const K& x ) const; |
(2) | (C++20 起) |
1) 檢查容器中是否存在鍵等同於 key 的元素。
2) 檢查是否存在鍵與值 x 比較等價的元素。此過載僅在限定 ID Compare::is_transparent 有效且表示一個型別時才參與過載決議。它允許在不構造
Key
例項的情況下呼叫此函式。目錄 |
[edit] 引數
key | - | 要搜尋的元素的鍵值 |
x | - | 可與鍵透明比較的任何型別的值 |
[edit] 返回值
如果存在這樣的元素則為 true ,否則為 false 。
[edit] 複雜度
容器大小的對數級別。
[edit] 示例
執行此程式碼
輸出
2: Found 5: Not found
[edit] 參閱
查詢具有特定鍵的元素 (public member function) | |
返回匹配特定鍵的元素數量 (public member function) | |
返回與特定鍵匹配的元素範圍 (public member function) |