C++ multimap equal_range()C++ multimap equal_range() function is used to return the boundary of the range containing all key elements in the container which is equal to x. If x does not match any key in the container, the return value range will be length 0 and both iterators will point to the nearest value greater than x. Otherwise, if x is greater than all elements in the container, it points to end. SyntaxThe range is defined by two iterators. It returns the bounds of a range that includes all the elements in the container which have a key equivalent to k. Parameterk: key to be searched in the multimap container. Return valueThis function returns pair. Where pair :: first is at the lower boundary of the range with the same value that lower_bound (x) would return, pair :: second is the same value as the upper_bound (x) would return, upper bound of the range it corresponds to. ComplexityLogarithmic in size. Iterator validityNo changes. Data RacesThe container is accessed (neither the const not non-const versions modify the container). No mapped values are accessed: concurrently accessing and modifying the elements is safe. Exception SafetyIf an exception is thrown, there are no changes in the container. Example 1Let's see the simple example: Output: Lower bound of b is: b = 2 Upper bound of b is: c = 3 In the above example, lower bound of b is b and upper bound of b is c. Example 2Let's see a simple example: Output: The lower bound is 3:0 The upper bound is 3:0 In the above example, equal_range() function returns 0 because it tries to find 10 which is not the key of the multimap mp. Example 3Let's see a simple example: Output: The lower bound of the element with a key of 2 in the multimap m1 is: 20. The upper bound of the element with a key of 2 in the multimap m1 is: 30. A direct call of upper_bound( 2 ) gives 30, matching the 2nd element of the pair returned by equal_range( 2 ). The multimap m1 doesn't have an element with a key less than 4. Example 4Let's see a simple example: Output: B, 1 Next TopicC++ Multimap |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India