I'm trying to understand the difference between declval<T>()
and declval<T&>()
? Is there an example where T&
can be used while T
cannot?
#include <type_traits>
#include <utility>
struct X {
X() = delete;
int func();
};
int main()
{
// works with both X as well as X& within declval
static_assert(std::is_same_v<decltype(std::declval<X&>().func()), int>);
}
Aucun commentaire:
Enregistrer un commentaire