5

To my surprise, I got an error, when I tried to compile this code with GCC 7.2.0.

Code:

#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:

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;
                                                              ^~~~~~~~~

I've been using increment for quite a while now with GCC 6.2.0 without a problem.

Which one is correct? If GCC 7 is correct, how do I write this metafunction?

SU3
  • 5,064
  • 3
  • 35
  • 66

0 Answers0