#include <iostream>
#include <mutex>
using namespace std;
#define DO_ONCE(callable) do { static bool _do_once_ = (callable(), true); (void)_do_once_; }while (false)
#define \
DO_ONCE2(callable) do { \
static std::once_flag _do_once_ ;\
std::call_once(_do_once_, callable); \
\
} while (false)
void once_log()
{
cout << "once call\n";
}
void call(int a)
{
DO_ONCE([a] {
cout << "once: " << a << endl;
});
DO_ONCE(once_log);
DO_ONCE2([a] {
cout << "once2: " << a << endl;
});
cout << "call: " << a << endl;
}
int main()
{
call(1);
call(2);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bXV0ZXg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKI2RlZmluZSBET19PTkNFKGNhbGxhYmxlKSBkbyB7IHN0YXRpYyBib29sIF9kb19vbmNlXyA9IChjYWxsYWJsZSgpLCB0cnVlKTsgKHZvaWQpX2RvX29uY2VfOyAgfXdoaWxlIChmYWxzZSkKCiNkZWZpbmUgXAogRE9fT05DRTIoY2FsbGFibGUpIGRvIHsgXAogc3RhdGljIHN0ZDo6b25jZV9mbGFnIF9kb19vbmNlXyA7XAogc3RkOjpjYWxsX29uY2UoX2RvX29uY2VfLCBjYWxsYWJsZSk7IFwKIFwKIAl9IHdoaWxlIChmYWxzZSkKCnZvaWQgb25jZV9sb2coKQp7Cgljb3V0IDw8ICJvbmNlIGNhbGxcbiI7CQp9Cgp2b2lkIGNhbGwoaW50IGEpCnsKCURPX09OQ0UoW2FdIHsKCQljb3V0IDw8ICJvbmNlOiAiIDw8IGEgPDwgZW5kbDsKCX0pOwoJCglET19PTkNFKG9uY2VfbG9nKTsKCQoJRE9fT05DRTIoW2FdIHsKCQljb3V0IDw8ICJvbmNlMjogIiA8PCBhIDw8IGVuZGw7Cgl9KTsKCQoJY291dCA8PCAiY2FsbDogIiA8PCBhIDw8IGVuZGw7Cn0KCmludCBtYWluKCkgCnsKCWNhbGwoMSk7CgljYWxsKDIpOwoKCXJldHVybiAwOwp9