【发布时间】:2021-08-22 19:38:01
【问题描述】:
我想了解declval<T>() 和declval<T&>() 之间的区别?有没有可以使用T& 而T 不能使用的例子?
#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>);
}
【问题讨论】: