Using the Capture Clause - C++ STL

C++ examples for STL:Lambda

Description

Using the Capture Clause

Demo Code

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

void ProcessVector(vector<int>& vect, int Exclude)
{
    for_each(vect.begin(), vect.end(), [Exclude](int x)
             {//  w  ww.  j  a  v a 2s  . c  o  m
                 if ((int)x != Exclude)
                    cout << x << endl;
             });
}

int main()
{
    vector<int> myV;
    myV.push_back(1);
    myV.push_back(2);
    myV.push_back(3);
    myV.push_back(4);

    ProcessVector(myV, 3);
}

Result


Related Tutorials