How do I do something like this, but in a way that will compile, and hopefully without insane typedefs?
auto b;
auto g;
if (vertical)
{
b = [=, &b_](int x, int y) -> bool { return b_[x + y*w]; };
g = [=, &g_](int x, int y) -> int& { return g_[x + y*w]; };
}
else
{
b = [=, &b_](int x, int y) -> bool { return b_[y + x*w]; };
g = [=, &g_](int x, int y) -> int& { return g_[y + x*w]; };
}
The
auto b;
andauto g;
would need to be initialised so that the compiler would be able to determined their type (but I think you know this).Since you don't seem to mind the specifics of type (you've declared them
auto
anyway);Should do the trick.
The reason this does not compile is the improper use of
auto
. You can avoid conditional creation of lambdas altogether by changing their definition a little:The idea is to set multipliers
mx
andmy
conditionally. This lets you construct your lambdas unconditionally, so you could useauto
in your declaration.