What is std :: set :: equal_range for?

Since it std::setcannot contain duplicate elements and is always sorted, std::set::equal_rangeit will always return a range that has no, no elements. Technically, yes, this is still a range, but what is the purpose of this algorithm? For std::setit seems rather unnecessary.

+6
source share
3 answers

I only guess. But howcount() , it makes some difference when you are in a template and do not want to determine if you are working on std::setor on some other associative container.

Basically, this is for consistency. The function performs as advertised, just that yes, it has dubious use compared to something like find()if you take it in isolation. This could potentially save you one manual iterator increase if you really want to get a half-open range out of the box .: P

+7
source

All associative containers support equal_range, which means that you can write a generic code that takes set, multiset, mapor multimap, and he will do the right thing.

+7
source

std:: multiset. , .

0

All Articles