Using the Auto Keyword to Automate the Return Type - C++ STL

C++ examples for STL:Lambda

Description

Using the Auto Keyword to Automate the 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 www .j av a  2  s  .  co  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);
}

Result


Related Tutorials