【发布时间】:2020-04-26 11:57:46
【问题描述】:
std::is_function 的以下实现如何?
template<class T>
struct is_function : std::integral_constant<
bool,
!std::is_const<const T>::value && !std::is_reference<T>::value
> {};
(来自CPP Reference)
在我看来,int 将是此定义下的函数。我错过了什么?
【问题讨论】:
-
想想
!is_const部分。 -
为什么函数类型不能是 const?这和可恶的类型有关吗?
-
@jtbandes 这是因为函数是 C++ 中少数不是对象的东西之一。
-
我猜是因为在某种意义上它总是 const
-
我觉得标题具有误导性。 “这是一个有效的 std::is_function 实现吗?”似乎更合适。