boost::range::adjacent_find

References

Headers

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

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

Examples

adjacent_find.cpp

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

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

    std::string::iterator eq_it = boost::range::adjacent_find(s);
    std::string::iterator gt_it = boost::range::adjacent_find(s, std::greater<char>());

    std::cout << "First duplicate character: '" << *eq_it << "' "
              << "at position " << (eq_it - s.begin()) << std::endl;
    std::cout << "First character greater than next: '" << *gt_it << "' "
              << "at position " << (gt_it - s.begin()) << std::endl;
    return 0;
}

Output:

First duplicate character: 'c' at position 2
First character greater than next: 'd' at position 4

 

Boost Range for Humans

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