1、实现分析
// Primary template.
/// Define a member typedef @c type only if a boolean constant is true.
template<bool, typename _Tp = void>
struct enable_if
{ };
// Partial specialization for true.
template<typename _Tp>
struct enable_if<true, _Tp>
{ typedef _Tp type; };
定义一个模版类,只有一个成员type定义;
通过 Partial specialization 完成条件为true时的type定义,其他情况为空,会有编译错误提示。