Since C++11, std::reference_wrapper
is a small "shim" template that is a class type that is constructible from and convertible to a reference type. It can be used in generic containers which might not otherwise support references.
https://en.cppreference.com/w/cpp/utility/functional/reference_wrapper
std::reference_wrapper is a class template that wraps a reference in a copyable, assignable object. It is frequently used as a mechanism to store references inside standard containers (like std::vector) which cannot normally hold references.
This standard library feature was deprecated in C++17 and is removed in the current draft of C++20. Why?
Is std::reference_wrapper
unsafe to use or defective in some way?
In http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0619r3.html#2.0
it appears that this is part considered part of "D.8 Old adaptable function bindings" and the text in the standard describing std::reference_wrapper
is crossed off in section "D.9.2 Typedefs to Support Function Binders [depr.func.adaptor.typedefs]"
It appears that we are removing it because of a role it played in an old function binder API, but it actually has additional uses in containers, as described on the reference page. Is there something I'm missing that replaces that use-case, or something else that I missed about this situation?
If this useful feature is being removed, should we implement it when we need it, or is there some reason that this whole pattern is unsafe?