Boost lambda::_1 in C++ 0x
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";});
精彩评论