I wanted to create a lambda in the following way:
auto l1 = condition ?
[](){ return true; } :
[number](){ return number == 123; };
However, I got error:
operands to ?: have different types ‘main()::<lambda()>’ and ‘main()::<lambda()>’
Obviously, the types seem to be the same. I thought, that capturing number
in only one of lambdas might be a problem, but I get the same error for these:
//check if capturing number in both lambdas would help
auto l2 = condition ?
[number](){ return true; } :
[number](){ return number == 123; };
//maybe the first lambda capture was optimised out? let's make sure:
auto l3 = condition ?
[number](){ return number != 123; } :
[number](){ return number == 123; };
I'm aware I can do it other way (below), but I'm wondering what is the cause of this behavior. It was compiled with GCC6.3.1, C++14 enabled.
//compiles
auto l4 = condition ?
[](const int){ return true; } :
[](const int number){ return number == 123; };