部分专业化并不是更专业化

时间:2017-10-08 04:34:56

标签: c++ templates gcc c++14 partial-specialization

令我惊讶的是,当我尝试使用GCC 7.2.0编译此代码时出现错误。

代码:

#include <typeinfo>
#include <iostream>
#include <utility>

template <typename Seq, typename Seq::value_type Inc> struct increment;
template <typename T, T... I, T Inc>                                   
struct increment<std::integer_sequence<T,I...>, Inc> {                 
  using type = std::integer_sequence<T,(I+Inc)...>;                    
};                                                                     

int main(int argc, char* argv[]) {
  typename increment<std::make_index_sequence<2>,1>::type seq;
  std::cout << typeid(seq).name() << std::endl;
}

错误:

error: partial specialization 'struct increment<std::integer_sequence<T, I ...>, Inc>' is not more specialized than [-fpermissive]
 struct increment<std::integer_sequence<T,I...>, Inc> {
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
spec.cc:5:62: note: primary template 'template<class Seq, typename Seq::value_type Inc> struct increment'
 template <typename Seq, typename Seq::value_type Inc> struct increment;
                                                              ^~~~~~~~~

我已经使用increment了很长一段时间GCC 6.2.0没有问题。

哪一个是正确的?如果GCC 7是正确的,我该如何编写这个元函数?

0 个答案:

没有答案