/* * function-objects-03.cc Standard Library, Funtion objects and Lambda expression, exercise 3. */ #include #include #include #include #include #include using namespace std; using namespace std::placeholders; template ostream& operator<<(ostream& os, const vector& v) { copy(begin(v), end(v), ostream_iterator(os, " ")); return os; } int main() { vector v{ 5, 4, 12, 8, 2, 1, 3, 10, 9, 7, 6, 11 }; cout << "\nValues in the vector:\n" << v << "\n\n"; ostream_iterator out(cout, " "); // a) cout << "Values in the vector greater than 5:\n"; copy_if(begin(v), end(v), out, [](int x){ return x > 5; }); cout << "\n\n"; // b) cout << "Values in the vector not equal to 10:\n"; copy_if(begin(v), end(v), out, [](int x){ return x != 10; }); cout << "\n\n"; // c) cout << "Multiply each value in the vector by 2:\n"; transform(begin(v), end(v), begin(v), [](int x){ return x*2;}); cout << v << "\n\n"; return 0; }