What benefits has using std::reference_wrapper
as template parameter of containers instead of raw pointers? That is std::vector<std::reference_wrapper<MyClass> >
vs. std::vector<MyClass*>
I like forgetting about nulls and not having to use pointer syntax, but the verbosity of the types (i.e. vector<reference_wrapper<MyClass> >
) plus having the call site use std::ref to wrap the actual reference makes me think it is not worth it.
I am referring to cases in which using std::shared_ptr or any other smart pointer is not an option.
Are there other benefits of using reference_wrapper or any other factors I am currently not taking into account? (I think my question applies to both C++11's reference_wrapper and boost's)
std::reference_wrapper<>
's implicit conversion operator to its::type&
. – underscore_d