abhijit jagdale
abhijit jagdale

Reputation: 649

Is there a way to get a pair having both the lower_bound and upper_bound in a sorted array?

If I have a std::vector having elements {1,1,1,2,2,2,3,3,3}

Is there a way to get a pair containing the lower_bound and upper_bound for value = 2 ?

Instead of me calling std::lower_bound and std::upper_bound separately.

Upvotes: 4

Views: 66

Answers (2)

Werner Henze
Werner Henze

Reputation: 16726

You could use std::equal_range.

Upvotes: 3

Casey
Casey

Reputation: 10936

Simply put, literally: std::equal_range

Upvotes: 3

Related Questions