Since C++ 17 one can write an if block that will get executed exactly once like this:
if
#include
static bool once = [] { std::cout << "Hello one-shot\n"; return false; }();
This solution is thread safe (unlike many of the other suggestions).