std::multiset<Key,Compare,Allocator>:: find
From cppreference.net
|
iterator find
(
const
Key
&
key
)
;
|
(1) | (constexpr since C++26) |
|
const_iterator find
(
const
Key
&
key
)
const
;
|
(2) | (constexpr since C++26) |
|
template
<
class
K
>
iterator find ( const K & x ) ; |
(3) |
(C++14부터)
(constexpr since C++26) |
|
template
<
class
K
>
const_iterator find ( const K & x ) const ; |
(4) |
(C++14부터)
(constexpr since C++26) |
1,2)
키가
key
와 동등한 요소를 찾습니다.컨테이너에 요청된 키를 가진 여러 요소가 있는 경우, 그 중 어느 하나가 반환될 수 있습니다.
3,4)
키가
x
와 동등하게 비교되는 요소를 찾습니다.
목차 |
매개변수
| key | - | 검색할 요소의 키 값 |
| x | - | 키와 투명하게 비교될 수 있는 임의의 타입의 값 |
반환값
요청된 요소에 대한 반복자. 해당 요소를 찾지 못한 경우, 끝 지난(past-the-end) (참조: end() ) 반복자가 반환됩니다.
복잡도
컨테이너 크기에 대해 로그 시간 복잡도를 가집니다.
참고 사항
| 기능 테스트 매크로 | 값 | 표준 | 기능 |
|---|---|---|---|
__cpp_lib_generic_associative_lookup
|
201304L
|
(C++14) | 연관 컨테이너 에서의 이종 비교 검색; ( 3,4 ) 오버로드 |
예제
이 코드 실행
#include <iostream> #include <set> struct LightKey { int x; }; struct FatKey { int x; int data[1000]; // a heavy blob }; // As detailed above, the container must use std::less<> (or other transparent // Comparator) to access these overloads. This includes standard overloads, // such as comparison between std::string and std::string_view. bool operator<(const FatKey& fk, const LightKey& lk) { return fk.x < lk.x; } bool operator<(const LightKey& lk, const FatKey& fk) { return lk.x < fk.x; } bool operator<(const FatKey& fk1, const FatKey& fk2) { return fk1.x < fk2.x; } int main() { // Simple comparison demo. std::multiset<int> example{1, 2, 3, 4}; if (auto search = example.find(2); search != example.end()) std::cout << "Found " << (*search) << '\n'; else std::cout << "Not found\n"; // Transparent comparison demo. std::multiset<FatKey, std::less<>> example2{{1, {}}, {2, {}}, {3, {}}, {4, {}}}; LightKey lk = {2}; if (auto search = example2.find(lk); search != example2.end()) std::cout << "Found " << search->x << '\n'; else std::cout << "Not found\n"; }
출력:
Found 2 Found 2
참고 항목
|
특정 키와 일치하는 요소의 수를 반환합니다
(public member function) |
|
|
특정 키와 일치하는 요소들의 범위를 반환합니다
(public member function) |