stl/lambda1.cpp

The following code example is taken from the book
The C++ Standard Library - A Tutorial and Reference, 2nd Edition
by Nicolai M. Josuttis, Addison Wesley Longman, 2012
Copyright © 2012 by Pearson Education, Inc. and Nicolai M. Josuttis


#include <algorithm>
#include <deque>
#include <iostream>
using namespace std;

int main()
{
    deque<int> coll = { 1, 3, 19, 5, 13, 7, 11, 2, 17 };

    int x = 5;
    int y = 12;
    auto pos = find_if (coll.cbegin(), coll.cend(),  // range
                        [=](int i) {                 // search criterion
                             return i > x && i < y;
                        });
    cout << "first elem >5 and <12: " << *pos << endl;
}