I have a colleague who keeps creating lambda functions to then call straight away, or in the code following it. For example:
int a = [&]
{
if (someField == constA)
{
return valueA;
}
else if (someField == constB)
{
return valueB;
}
return valueC;
}();
In this case, a simple one-line ternary would suffice, and be just as easy to read (and he doe use ternaries, albeit poorly-formatted nested ones). Some of his other uses involve giving the lambda function a name, and then calling it from a loop under it. There's no reason these lambda functions can't be member functions. I'm pretty sure the compiler will inline them.
It compiles. It works. But it's weird and difficult to parse mentally, especially when he's calling his lambda from a loop under it. I'm trying to steer him towards simpler code.
Is it just my problem because I'm not expecting it, or is that weird to anyone else?