// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
#include <iostream>
#include <cstddef>
#include <mutex>
#include <chrono>

using namespace std;
using namespace std::chrono;

#include "CallOnceSingleton11.h"

once_flag CallOnceSingleton11::flag;

CallOnceSingleton11* CallOnceSingleton11::instance = nullptr;

CallOnceSingleton11::CallOnceSingleton11()
{
    cout << "  Constructed\t: " << duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count() << endl;
}

void CallOnceSingleton11::Init()
{
    instance = new CallOnceSingleton11();
}

CallOnceSingleton11& CallOnceSingleton11::Instance()
{
    call_once(flag, Init);
    cout << "  Retrieved\t: " << duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count() << endl;
    return *instance;
}

void CallOnceSingleton11::Something()
{
    cout << "  Called\t: " << duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count() << endl;
}
