std::map<Key,T,Compare,Allocator>::contains
来自 cppreference.cn
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) |