【发布时间】:2017-04-23 13:46:24
【问题描述】:
我不熟悉 cpp 中的模板魔法。在阅读了 link 中“TemplateRex”所说的内容后,我对 std::is_intergral 的工作原理感到困惑。
template< class T >
struct is_integral
{
static const bool value /* = true if T is integral, false otherwise */;
typedef std::integral_constant<bool, value> type;
};
我可以理解 SFINAE 的工作原理以及特征的工作原理。在引用cppreference 后,发现了“is_pointer”的实现,而不是看起来像这样的“is_integral”:
template< class T > struct is_pointer_helper : std::false_type {};
template< class T > struct is_pointer_helper<T*> : std::true_type {};
template< class T > struct is_pointer : is_pointer_helper<typename std::remove_cv<T>::type> {};
'is_integral' 有类似的实现吗?怎么样?
【问题讨论】:
标签: c++11 templates typetraits