How to avoid decay of std::reference_wrapper to plain references in std::make_tuple?
-
14-07-2021 - |
سؤال
I' am trying to correctly produce a tuple of std::reference_wrapper
s 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_wrapper
s 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_wrapper
s 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.
لا تنتمي إلى StackOverflow