std::flat_multiset<Key,Compare,KeyContainer>:: contains
From cppreference.net
<
cpp
|
container
|
flat multiset
C++
Containers library
|
(C++17)
|
||||
| Sequence | ||||
|
(C++11)
|
||||
|
(C++26)
|
||||
|
(C++26)
|
||||
|
(C++11)
|
||||
| Associative | ||||
| Unordered associative | ||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
| Adaptors | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
| Views | ||||
|
(C++20)
|
||||
|
(C++23)
|
||||
| Tables | ||||
| Iterator invalidation | ||||
| Member function table | ||||
| Non-member function table |
std::flat_multiset
| Member types | ||||
| Member functions | ||||
| Non-member functions | ||||
| Helper classes | ||||
| Tags | ||||
| Deduction guides | ||||
|
bool
contains
(
const
Key
&
key
)
const
;
|
(1) |
(自 C++23 起)
(自 C++26 起为 constexpr) |
|
template
<
class
K
>
bool contains ( const K & x ) const ; |
(2) |
(自 C++23 起)
(自 C++26 起为 constexpr) |
1)
检查容器中是否存在键等价于
key
的元素。
2)
检查是否存在与
x
比较等价的键的元素。
目录 |
参数
| key | - | 要搜索元素的键值 |
| x | - | 可与键进行透明比较的任意类型值 |
返回值
true 表示存在这样的元素,否则为 false 。
复杂度
与容器大小呈对数关系。
示例
运行此代码
#include <iostream> #include <flat_set> int main() { std::flat_multiset<int> example{1, 2, 3, 4}; for (int x : {2, 5}) if (example.contains(x)) std::cout << x << ": Found\n"; else std::cout << x << ": Not found\n"; }
输出:
2: Found 5: Not found
参见
|
查找具有特定键的元素
(公开成员函数) |
|
|
返回匹配特定键的元素数量
(公开成员函数) |
|
|
返回匹配特定键的元素范围
(公开成员函数) |