Relying on compiler detection of return type - C++ STL

C++ examples for STL:Lambda

Description

Relying on compiler detection of return type

Demo Code

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

using namespace std; 

void ProcessVector(vector<int>& vect) 
{ 
    vector<bool> Result; 
    Result.resize(vect.size()); //from w w  w  .  j a v  a  2 s  .c  o 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); 
}

Result


Related Tutorials