Since std::set
cannot contain duplicate elements and is always sorted, std::set::equal_range
will always return the range that has either none or 1 element. Technically, yes, that's still a range, but what is the purpose of this algorithm? For std::set
it seems pretty unnecessary.
equal_range in C++ std::equal_range is used to find the sub-range within a given range [first, last) that has all the elements equivalent to a given value. It returns the initial and the final bound of such a sub-range.
std::set is an associative container that contains a sorted set of unique objects of type Key . Sorting is done using the key comparison function Compare. Search, removal, and insertion operations have logarithmic complexity. Sets are usually implemented as red-black trees.
The set::equal_range() is a built-in function in C++ STL which returns an iterator of pairs.
so yes, order is guaranteed by the C++ standard.
All of the associative containers support equal_range
, which means you can write generic code which accepts a set
, multiset
, map
or multimap
and it will do the right thing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With