Search code examples
c++c++11tuplesreference-wrapper

How to avoid decay of std::reference_wrapper to plain references in std::make_tuple?


I' am trying to correctly produce a tuple of std::reference_wrappers to objects. By using the technique shown here I manage to map the std::ref function over all the original tuple, however, according to this (and it actually happens), std::reference_wrappers decay to plain refs (&) in the process. Is there a way to avoid this? I have a whole set of function that accept tuples of std::reference_wrappers and I'd rather not change them to use references.

Thanks


Solution

  • It is sufficient to do

    tuple<reference_wrapper<T>...> = /* my tuple of references */;