开发者

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";});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜