while reading some SO questions regarding c++ templates and generally code I did not write I came across using such construct:
template<class T>
std::add_lvalue_reference_t<T> my_foo(T &t) { /*do some stuff and return*/ }
On the other hand I have been always using something like this:
template<class T>
T &my_foo(T &t) { /*do some stuff and return*/ }
And so I have a few questions:
- Are these snippets of code equivalent?
- If not, what is the difference between them?
- If not, which is to be prefered?