Suppose I have a function returning an expensive object and I want it to call exactly once while having an access to return value of the function.
Is this achievable with std::once_flag and std::call_once or I need to go with boolean flags, etc..?
Simple example:
using namespace boost::interprocess;
shared_mempry_object openOrCreate(const char* name)
{
shared_memory_object shm(open_or_create, name, read_write);
return shm;
}
I there a way to call this function from some routine and ensure only calling once with mentioned primitives while maintaining return value?