Skip to content

Instantly share code, notes, and snippets.

@michaelcontento
Last active December 28, 2015 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelcontento/f2f470a53ac4dc541729 to your computer and use it in GitHub Desktop.
Save michaelcontento/f2f470a53ac4dc541729 to your computer and use it in GitHub Desktop.
std::function<void()> once(const std::function<void()>& callback)
{
return [&callback]() {
static bool called = false;
if (!called) {
called = true;
callback();
}
};
}
bool MyClass::init()
{
static auto wuhu = once([](){ log("WUHU!"); });
wuhu();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment