2

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:

  1. Are these snippets of code equivalent?
  2. If not, what is the difference between them?
  3. If not, which is to be prefered?
bartop
  • 9,971
  • 1
  • 23
  • 54
  • Take a look at https://stackoverflow.com/a/5108295/5212827. Might be a duplicate. – DeiDei Feb 13 '18 at 19:35
  • You can infer the difference through a [reference](http://en.cppreference.com/w/cpp/types/add_reference). – chris Feb 13 '18 at 19:36

0 Answers0