C++ transform() with Lambda Expressions

Description

C++ transform() with Lambda Expressions

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

using namespace std; 

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

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

    cout.setf(ios::boolalpha); 
    for_each(Result.begin(), Result.end(), 
             [](bool x){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); 
}



PreviousNext

Related