Difference between revisions of "cpp/container/map/equal range"
From cppreference.com
m (Shorten template names. Use {{lc}} where appropriate.) |
(subst:) |
||
Line 1: | Line 1: | ||
− | {{ | + | {{cpp/container/map/title | equal_range}} |
+ | {{cpp/container/map/navbar}} | ||
+ | {{dcl begin}} | ||
+ | {{dcl |num=1| | ||
+ | std::pair<iterator,iterator> equal_range( const Key& key ); | ||
+ | }} | ||
+ | {{dcl |num=2| | ||
+ | std::pair<const_iterator,const_iterator> equal_range( const Key& key ) const; | ||
+ | }} | ||
+ | {{cpp/container/if ord | map | ||
+ | |{{dcl | num=3 | since=c++14 | | ||
+ | template< class K > | ||
+ | std::pair<iterator,iterator> equal_range( const K& x ); | ||
+ | }} | ||
+ | {{dcl | num=4 | since=c++14 | | ||
+ | template< class K > | ||
+ | std::pair<const_iterator,const_iterator> equal_range( const K& x ) const; | ||
+ | }} | ||
+ | }} | ||
+ | {{dcl end}} | ||
+ | |||
+ | @1,2@ Returns a range containing all elements with key {{tt|key}} in the container. {{cpp/container/if ord|map | ||
+ | |The range is defined by two iterators, one pointing to the first element that is ''not less'' than {{tt|key}} and another pointing to the first element ''greater'' than {{tt|key}}. The first iterator may be alternatively obtained with {{lc|lower_bound()}}, the second - with {{lc|upper_bound()}}. | ||
+ | |The range is defined by two iterators, the first pointing to the first element of the wanted range and the second pointing past the last element of the range. | ||
+ | }} | ||
+ | |||
+ | {{cpp/container/if ord | map | ||
+ | |@3,4@ Same as {{v|1,2}}, but compares the keys to the value {{tt|x}}. These templates only participate in overload resolution if the type {{c|Compare::is_transparent}} exists. They allow calling this function without constructing an instance of {{tt|Key}}. | ||
+ | }} | ||
+ | |||
+ | ===Parameters=== | ||
+ | {{par begin}} | ||
+ | {{par | key | key value to compare the elements to}} | ||
+ | {{cpp/container/if assoc | map | | ||
+ | {{par | x | alternative value that can be compared to {{tt|Key}} }} | ||
+ | }} | ||
+ | {{par end}} | ||
+ | |||
+ | ===Return value=== | ||
+ | {{cpp/container/if ord|map | ||
+ | |{{lc|std::pair}} containing a pair of iterators defining the wanted range: the first pointing to the first element that is not ''less'' than {{tt|key}} and the second pointing to the first element ''greater'' than {{tt|key}}. | ||
+ | |||
+ | If there are no elements ''not less'' than {{tt|key}}, past-the-end (see {{lc|end()}}) iterator is returned as the first element. Similarly if there are no elements ''greater'' than {{tt|key}}, past-the-end iterator is returned as the second element. | ||
+ | |{{lc|std::pair}} containing a pair of iterators defining the wanted range. If there are no such elements, past-the-end (see {{lc|end()}}) iterators are returned as both elements of the pair. | ||
+ | }} | ||
+ | |||
+ | ===Complexity=== | ||
+ | {{cpp/container/if ord|map | ||
+ | |Logarithmic in the size of the container. | ||
+ | |Average case constant, worst case linear in the size of the container. | ||
+ | }} | ||
+ | |||
+ | ===See also=== | ||
+ | {{dsc begin}} | ||
+ | {{dsc inc | cpp/container/dsc find |map}} | ||
+ | {{cpp/container/if ord|map | ||
+ | |{{dsc inc | cpp/container/dsc upper_bound |map}} | ||
+ | {{dsc inc | cpp/container/dsc lower_bound |map}} | ||
+ | }} | ||
+ | {{dsc end}} | ||
[[de:cpp/container/map/equal range]] | [[de:cpp/container/map/equal range]] |
Revision as of 07:51, 30 August 2013
std::pair<iterator,iterator> equal_range( const Key& key ); |
(1) | |
std::pair<const_iterator,const_iterator> equal_range( const Key& key ) const; |
(2) | |
template< class K > std::pair<iterator,iterator> equal_range( const K& x ); |
(3) | (since C++14) |
template< class K > std::pair<const_iterator,const_iterator> equal_range( const K& x ) const; |
(4) | (since C++14) |
1,2) Returns a range containing all elements with key
key
in the container. The range is defined by two iterators, one pointing to the first element that is not less than key
and another pointing to the first element greater than key
. The first iterator may be alternatively obtained with lower_bound(), the second - with upper_bound().3,4) Same as (1,2), but compares the keys to the value
x
. These templates only participate in overload resolution if the type Compare::is_transparent exists. They allow calling this function without constructing an instance of Key
.Contents |
Parameters
key | - | key value to compare the elements to |
x | - | alternative value that can be compared to Key
|
Return value
std::pair containing a pair of iterators defining the wanted range: the first pointing to the first element that is not less than key
and the second pointing to the first element greater than key
.
If there are no elements not less than key
, past-the-end (see end()) iterator is returned as the first element. Similarly if there are no elements greater than key
, past-the-end iterator is returned as the second element.
Complexity
Logarithmic in the size of the container.
See also
finds element with specific key (public member function) | |
returns an iterator to the first element greater than the given key (public member function) | |
returns an iterator to the first element not less than the given key (public member function) |