adjacent_find()
By default, looks for the first adjacent pair of duplicate elements. A binary operator can override the built-in equality operator. Returns an iterator that addresses the first element of the pair.
#include <algorithm> class TwiceOver { public: bool operator() ( int val1, int val2 ) { return val1 == val2/2 ? true : false; } }; piter = adjacent_find( ia, ia+8 ); iter = adjacent_find( vec.begin(), vec.end(), TwiceOver() );
Get Essential C++ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.