boost::range::binary_search

References

Headers

boost::range::binary_search is available by including any of the following headers:

  • boost/range/algorithm/binary_search.hpp or
  • boost/range/algorithm.hpp

Examples

binary_search.cpp

#include <iostream>
#include <boost/range/algorithm.hpp>

int main() {
    std::string s = "abcddefghijkklmnoopqrstuvwxyyyz";

    // Binary search to determine if a value is contained in a range.
    // Accepts an optional ordering pradicate.
    // Returns true if the value was found, false otherwise.
    bool has_n = boost::range::binary_search(s, 'n');

    std::cout << (has_n ? "'n' is in s" : "'n' is not in s") << std::endl;
    return 0;
}

Output:

'n' is in s

 

Boost Range for Humans

This reference is part of Boost Range for Humans. Click the link to the overview.