#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";
};
