mercredi 28 avril 2021

Using declval with a reference type

I see some code examples where the type used to instantiate the std::declval template function is specified as a reference type rather than just a type, as in:

std::declval<T &>()

as opposed to:

std::declval<T>()

where T is some type. I am missing the subtlety why the reference notation might be chosen overe the plain type. Would someone please explain this to me ?

I know that std::declval expands to typename std::add_rvalue_reference<T>::type but I am still missing the reason why one would instantiate the latter with a reference to a type rather than the plain type itself.

Aucun commentaire:

Enregistrer un commentaire