0

How to use STL binary search operations with pairs ? I also wish to use lower_bound function . Is it possible ?

Maggi Iggam
  • 682
  • 1
  • 8
  • 20

1 Answers1

2

std::pair overloads the operator< thus any algorithm that uses ordering will work with pairs (assuming you've overloaded operator< for the pair members). The ordering is first by the first member and then by second if the first parts are equal. The lower_bound function that takes no predicate as argument uses the operator< for the comparison, thus it will work for pairs too.

Ivaylo Strandjev
  • 69,226
  • 18
  • 123
  • 176