#include<iostream>
#define CONCATE_(X,Y) X##Y
#define CONCATE(X,Y) CONCATE_(X,Y)
#define UNIQUE(NAME) CONCATE(NAME, __LINE__)
struct Static_
{
template<typename T> Static_ (T lambda) { lambda(); }
~Static_ () {} // to counter unused variable warning
};
#define STATIC static Static_ UNIQUE(block) = [&]() -> void
void foo ()
{
std::cout << "foo()\n";
STATIC
{
std::cout << "Executes only once inside foo()\n";
};
}
int main ()
{
std::cout << "main()\n";
foo();
foo();
foo();
}
STATIC
{
std::cout << "Executes only once before main()\n";
};
I2luY2x1ZGU8aW9zdHJlYW0+CgojZGVmaW5lIENPTkNBVEVfKFgsWSkgWCMjWQojZGVmaW5lIENPTkNBVEUoWCxZKSBDT05DQVRFXyhYLFkpCiNkZWZpbmUgVU5JUVVFKE5BTUUpIENPTkNBVEUoTkFNRSwgX19MSU5FX18pCgpzdHJ1Y3QgU3RhdGljXwp7CiAgdGVtcGxhdGU8dHlwZW5hbWUgVD4gU3RhdGljXyAoVCBsYW1iZGEpIHsgbGFtYmRhKCk7IH0KICB+U3RhdGljXyAoKSB7fSAgLy8gdG8gY291bnRlciB1bnVzZWQgdmFyaWFibGUgd2FybmluZwp9OwoKI2RlZmluZSBTVEFUSUMgc3RhdGljIFN0YXRpY18gVU5JUVVFKGJsb2NrKSA9IFsmXSgpIC0+IHZvaWQKCnZvaWQgZm9vICgpCnsKICBzdGQ6OmNvdXQgPDwgImZvbygpXG4iOwogIFNUQVRJQwogIHsKICAgIHN0ZDo6Y291dCA8PCAiRXhlY3V0ZXMgb25seSBvbmNlIGluc2lkZSBmb28oKVxuIjsKICB9OyAgCn0KCmludCBtYWluICgpCnsKICBzdGQ6OmNvdXQgPDwgIm1haW4oKVxuIjsKICBmb28oKTsKICBmb28oKTsKICBmb28oKTsKfQoKU1RBVElDCnsKICBzdGQ6OmNvdXQgPDwgIkV4ZWN1dGVzIG9ubHkgb25jZSBiZWZvcmUgbWFpbigpXG4iOwp9Owo=