c++11 - C++ lambda with a function call insde -


the following lambda expression code failing compile in vc++ 2010.

void error_check() {}  int main() {     vector<int> v(10);     std::generate(v.begin(), v.end(), [](){ //either add -> int,          error_check(); //or comment out compile         return rand()%99; }); } 

the compiler says "a lambda has been specified have void return type cannot return value." however, if explicitly specify return type or comment out error_check(); code compiles fine.

i read return type part can omitted single return statements. why required above?

in c++11, "single return statement" required lambda (or constexpr function) means return expression; only thing in function definition. can't have statement before return statement.

c++1y more generous sort of thing, , should allow code posted.

besides going ahead , adding trailing return type, work around comma operator:

[](){     return (error_check(), rand()%99); } 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -