其實這是早已踩過的 bug, 單純留著當紀錄.
int i = 0;
( [&i]() {
// capture once
++i;
( [&i]() {
// capture twice
++i;
} )();
} )();
std::cout << i << std::endl; // 2
來猜猜看上述程式用哪個 compiler 會出錯?
int i = 0;
( [&i]() {
// capture once
++i;
( [&i]() {
// capture twice
++i;
} )();
} )();
std::cout << i << std::endl; // 2
auto f( std::bind( []( int a, int b )->int {
return a + b;
}, std::placeholders::_1, 2 ) );
f( 1 ); // returns 3