Say I have a set, like such:
my_set = {"aaron", "cathy", "john", "stewie", "xavier"};
Say I want a function like such:
FindFirst(my_set, "a") // returns an iterator pointing to "aaron"
FindFirst(my_set, "aaron") // returns an iterator pointing to "aaron"
FindFirst(my_set, "bill") // returns an iterator pointing to "cathy"
FindFirst(my_set, "zzzzz") // returns past-the-end iterator
Basically, it takes a value and returns an iterator either to that element, or the first element after it (picking the past-the-end iterator if the value provided would lie after the end of the set).
Does any function like this exist in the standard library, or am I going to have to write one myself?
set::lower_bound
is the function you are looking for.
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