std::flat_set<Key,Compare,KeyContainer>:: contains
From cppreference.net
|
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_set<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
참고 항목
|
특정 키를 가진 요소를 찾습니다
(public member function) |
|
|
특정 키와 일치하는 요소의 개수를 반환합니다
(public member function) |
|
|
특정 키와 일치하는 요소들의 범위를 반환합니다
(public member function) |