Lambda, closures, surprises

Let’s start with a question. Is the following legal (compile + link) C++ code:

const bool myBool1 = [](){ return false; };

If you said yes, it’s legal, and obviously myBool1 is initialized to false. You’re partially right, but you might be surprised. It is in fact, legal code. However, here’s the surprise. The valiable myBool1 is in fact initialized to true. How can that be?

Continue readingLambda, closures, surprises