Saving links using reference_wrapper possible:
std::reference_wrapper guaranteed to be TriviallyCopyable. (since C ++ 17)
Just having a non-trivial nonspecific constructor (e.g. std::reference_wrapper<T>::reference_wrapper(T&) ) is absolutely normal. The same goes for your trivially_copyable_tuple ; if it has a trivial copy constructor, trivially_copyable_tuple::trivially_copyable_tuple(int&, float&, char) fine.
And generally, you do not need to use std::reference_wrapper ; while the reference type is not TriviallyCopyable, the class type containing the link itself is TriviallyCopyable (although it is not Pod, StandardLayoutType, DefaultConstructible, TriviallyDefaultConstructible or Trivial).
Here are some examples:
- my own set of tuples , showing that no special tricks are required to create it TriviallyCopyable;
- a slightly more complicated implementation showing that if you provide reassignment of assignability (so you need to use
reference_wrapper -alike inside), you can still save all other properties; - a assignable tuple showing that you are losing the trivial ability to copy, but only on tuples that actually contain a reference type; you can keep the trivial ability to copy on tuples containing scalars.
source share