C++ Lambda Expressions Using the Auto Keyword to Automate the Return Type

Description

C++ Lambda Expressions Using the Auto Keyword to Automate the Return Type

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

using namespace std;

void ProcessVector(vector<int>& vect)
{
    vector<bool> Result;
    Result.resize(vect.size());/*w  w w  .  j ava 2 s .  c o m*/

    auto Transformer = [](int x){return x > 3;};
    transform(vect.begin(), vect.end(), Result.begin(),
              Transformer);

    cout.setf(ios::boolalpha);
    auto DoPrint = [](bool x){cout << x << endl;};
    for_each(Result.begin(), Result.end(),
             DoPrint);
}

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

    ProcessVector(myV);
}



PreviousNext

Related