4 ms·
cppreference explains it pretty well: >std::reference_wrapper is a class template that wraps a reference in a copyable, assignable object. It is frequently use
by andrepd 9y ago
cppreference explains it pretty well:
>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.
>Specifically, std::reference_wrapper is a CopyConstructible and CopyAssignable wrapper around a reference [...] of type T. Instances of std::reference_wrapper are objects (they can be copied or stored in containers) but they are implicitly convertible to T&, so that they can be used as arguments with the functions that take the underlying type by reference.
Sounds pretty reasonable and useful to me. No need for over-the-top head banging :)
- mannykannot 9y agoIt is also an example of a sort of 'combinatorial pump' that inflates the language's complexity, as each new feature needs to work with every existing one. It is my guess that it is C++'s multi-paradigm flexibility that makes this both possible and necessary.