我惊讶地发现,对于某些T
,decltype(std::declval<T>())
是不合法的:
#include <utility>
template<typename T>
using Alias = decltype(std::declval<T>());
// as expected
using A1 = Alias<int>;
using A2 = Alias<int(int)>;
// error: no matching function for call to 'declval<...>()'
using A3 = Alias<int(int) const>;
using A4 = Alias<int(int) volatile>;
using A5 = Alias<int(int) &>;
using A6 = Alias<int(int) &&>;
// and all combinations of the above
cppreference似乎并未表明此错误是预期的。
还有其他declval<T>
不能使用的类型吗?规范在哪里定义这些?