'typename Enable = void'是什么意思?

时间:2015-12-25 02:54:27

标签: c++ templates

我发现ProtoBuf中已定义typename Enable = void

template<typename T, typename Enable = void>
struct RefTypeTraits;

但是,我找不到此header file中使用的Enable,这让我感到困惑。 typename Enable = void在模板中的含义是什么?

2 个答案:

答案 0 :(得分:5)

允许SFINAE使用模板专业化,如

template<typename T>
struct RefTypeTraits<T, std::enable_if_t<some_condition<T>::value>> {
    // ... specialization for T which respects condition
};

答案 1 :(得分:3)

您的模板只有两个模板参数。第二个名为“Enabled”,默认类型为“void”。这是后来允许SFINAE的一个技巧。

相关问题