令我惊讶的是,当我尝试使用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
是正确的,我该如何编写这个元函数?