What benefits has using std::reference_wrapper
as template parameter of containers instead of raw pointers? That is std::vector
C references are really problematic while working with templates. If you are "lucky" enough to compile code with reference as a template parameter you might have problems with code that would work (for some reason) as follows:
template f(T x) { g(x); }
template g(T x) { x++; }
Then even if you call f
it will call g
. But reference_wrapper
works fine with templates.
As also mentioned earlier - you will have problems with compiling things like vector
, but vector
works fine.