3

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

Community
  • 1
  • 1
tunnuz
  • 22,374
  • 30
  • 88
  • 127

2 Answers2

0

It is sufficient to do

tuple<reference_wrapper<T>...> = /* my tuple of references */;
tunnuz
  • 22,374
  • 30
  • 88
  • 127
0

In case it is possible to change the wrapper type, using boost::reference_wrapper / boost::ref could be a solution to the problem.

usta
  • 6,519
  • 3
  • 21
  • 38