Assume the following sketch:
struct C {
(either T or T&) m_t;
C(T& t):
(instantiate m_t as T& m_t(t))
{}
C(T&& t):
(instantiate m_t as T(t))
{}
};
such that a C
either has or has not ownership of t
, depending on how the C
was constructed. Is that possible, possibly without resorting to shared_ptr
and thus having to move everything to heap? I'm trying around with std::variant
, but without success so far.