int main()
{
std::vector<int> v;
v.push_back(1);
v.push_back(3);
v.push_back(2);
std::for_each(v.begin(), v.end(), std::cout << boost::lambda::_1 << "\n");
}
Can this code be translated to C++ without using Boost? I know C++ 0x lambda expression syntax, but didn't try to use placeholders in such context.
No placeholder needed in this case, as lambdas capture the parameter:
std::for_each(v.begin(), v.end(), [](int x){std::cout << x << "\n";});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With