std::flat_map<Key,T,Compare,KeyContainer,MappedContainer>:: equal_range
|
std::
pair
<
iterator, iterator
>
equal_range
(
const
Key
&
key
)
;
|
(1) |
(C++23부터)
(C++26부터 constexpr) |
|
std::
pair
<
const_iterator, const_iterator
>
equal_range ( const Key & key ) const ; |
(2) |
(C++23부터)
(C++26부터 constexpr) |
|
template
<
class
K
>
std:: pair < iterator, iterator > equal_range ( const K & x ) ; |
(3) |
(C++23부터)
(C++26부터 constexpr) |
|
template
<
class
K
>
std::
pair
<
const_iterator, const_iterator
>
|
(4) |
(C++23부터)
(C++26부터 constexpr) |
주어진 키를 가진 모든 요소를 포함하는 범위를 반환합니다. 이 범위는 두 개의 반복자로 정의되며, 하나는 주어진 키보다 작지 않은 첫 번째 요소를 가리키고 다른 하나는 주어진 키보다 큰 첫 번째 요소를 가리킵니다.
또는 첫 번째 반복자는 lower_bound() 로 얻을 수 있고, 두 번째 반복자는 upper_bound() 로 얻을 수 있습니다.
목차매개변수
반환값std::pair 원하는 범위를 정의하는 한 쌍의 반복자를 포함하는:
복잡도컨테이너 크기에 대해 로그 시간 복잡도를 가집니다. 예제
이 코드 실행
#include <iostream> #include <flat_map> int main() { const std::flat_map<int, const char*> m { {0, "zero"}, {1, "one"}, {2, "two"} }; auto p = m.equal_range(1); for (auto& q = p.first; q != p.second; ++q) std::cout << "m[" << q->first << "] = " << q->second << '\n'; if (p.second == m.find(2)) std::cout << "end of equal_range (p.second) is one-past p.first\n"; else std::cout << "unexpected; p.second expected to be one-past p.first\n"; auto pp = m.equal_range(-1); if (pp.first == m.begin()) std::cout << "pp.first is iterator to first not-less than -1\n"; else std::cout << "unexpected pp.first\n"; if (pp.second == m.begin()) std::cout << "pp.second is iterator to first element greater-than -1\n"; else std::cout << "unexpected pp.second\n"; auto ppp = m.equal_range(3); if (ppp.first == m.end()) std::cout << "ppp.first is iterator to first not-less than 3\n"; else std::cout << "unexpected ppp.first\n"; if (ppp.second == m.end()) std::cout << "ppp.second is iterator to first element greater-than 3\n"; else std::cout << "unexpected ppp.second\n"; } 출력: m[1] = one end of equal_range (p.second) is one-past p.first pp.first is iterator to first not-less than -1 pp.second is iterator to first element greater-than -1 ppp.first is iterator to first not-less than 3 ppp.second is iterator to first element greater-than 3 참고
|