Defining a Problem Solved by Lambda Expressions - C++ STL Algorithm

C++ examples for STL Algorithm:for_each

Description

Defining a Problem Solved by Lambda Expressions

Demo Code

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

using namespace std;

class MyFunctor/* w  w w  .ja va 2 s .  c  o  m*/
{
public:
    void operator()(int x)
    {
        cout << x << endl;
    }
};

void ProcessVector(vector<int>& vect)
{
    MyFunctor Func;
    for_each(vect.begin(), vect.end(), Func);
}

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

    ProcessVector(myV);
}

Result


Related Tutorials