سؤال

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

هل كانت مفيدة؟

المحلول

It is sufficient to do

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

نصائح أخرى

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top