Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 497
Alex F Avatar asked Aug 28 '11 10:08

Alex F


1 Answers

No placeholder needed in this case, as lambdas capture the parameter:

std::for_each(v.begin(), v.end(), [](int x){std::cout << x << "\n";});
like image 109
Diego Sevilla Avatar answered Nov 17 '22 07:11

Diego Sevilla