I need a trivially copyable tuple-like class, but no suitable implementations exist, I could not come up with one myself and I think one might even not be possible. The reason for it are references. A
Storing references using
reference_wrapper is entirely possible:
std::reference_wrapperis guaranteed to be TriviallyCopyable. (since C++17)
Just having a non-trivial non-special constructor (as e.g.
std::reference_wrapper<T>::reference_wrapper(T&)) is absolutely fine. So the same holds for your
trivially_copyable_tuple; as long as it has a trivial copy constructor,
trivially_copyable_tuple::trivially_copyable_tuple(int&, float&, char) is fine.
And actually, you don't need to use
std::reference_wrapper at all; while a reference type is not TriviallyCopyable, a class type containing a reference is itself TriviallyCopyable (although it is not Pod, StandardLayoutType, DefaultConstructible, TriviallyDefaultConstructible, or Trivial).
Here's a few examples:
reference_wrapper-alike internally) you can still preserve all the other properties;