I find shared_memory_object constructor semantics to be rather inconvenient for embedding it into anotherclass.
Consider the following
class A
{
public:
A(int type) : shm_(pass params to the shared_memory_object ctor)
{
}
private:
shared_memory_object shm_;
};
If my class A is such that a shared_memory_object needs to be called with either create_only or open_only based on
the type passed to A's constructor, I can't do it easily.
i.e. some thing like
A(int type) : shm_(type == something ? create_only : open_only) {}
This won't work because create_only & open_only are different types & this will call 2 different overloaded constructors,
hence the above code will not compile.
Alternatives here are
1) make A a templated class instead of having type as a ctor param.
i.e.
template <class T>
class A
{
public:
A() : shm_(T(), other params) {}
};
then use
A<create_only> a;
A<open_only> b;
OR
2) Keep a shared_memory_object ptr inside non-templated class A instead of an actual object
and create it dynamically.
Assuming, I don't want to use either of these options, is there any other nifty trick anyone can think of to achieve what I want to do?