C++ transform()
on vector
#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 . ja v a2 s .c om*/ 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); }