更新时间:2023-12-01 08:03:52
is_pair_v<std::iterator_traits<typename Container::iterator>::value_type>
应该
is_pair_v<typename std::iterator_traits<typename Container::iterator>::value_type>
因为 value_type
是一种类型.如果没有 typename
,它将被解析为一个值并且使 enable_if
失败,从而回退到主模板.
because value_type
is a type. Without the typename
, it will be parsed as a value and fail the enable_if
, thus falling back to the primary template.
您在 main
中的测试产生正确值的原因是因为那里的模板已经实例化并且 value_type
是类型还是值没有歧义.
The reason your tests in main
yield the correct value is because the templates there have already been instantiated and there is no ambiguity whether value_type
is a type or value.
第二个错误是您的主要模板
The second error is your primary template
template<typename...>
应该是
template<typename, typename = void>
否则,is_mapping
永远不会是具有两个参数的特化,因为参数计数不匹配.
Otherwise, is_mapping<T>
will never be the specialization with two arguments because the argument count mismatch.