peterSweter
peterSweter

Reputation: 653

Template argument specialization example from cpprefference.com doesn't work

I found this example on http://en.cppreference.com/w/cpp/language/partial_specialization

template <int I, int J, int K> struct B {};
template <int I> struct B<I, I*2, 2> {};  // OK: first parameter is deducible

I have errors while compiling it with -std=c++11 and -std=c++14

How to compile this? Or maybe example is wrong?

error: template argument ‘(I * 2)’ involves template parameter(s)
 template <int I> struct B<I, I*2, 2> {};  // OK: first parameter is deducible

Upvotes: 4

Views: 105

Answers (1)

user743382
user743382

Reputation:

This is a recent language change, and even the current releases of several compilers don't implement it yet. It's CWG issue 1315, which lists the status as "tentatively ready", though according to @bogdan in the comments, the change has already been accepted into the standard. Prior to that change, it was invalid for exactly the reason that your compiler shows in its error message.

Changing GCC's behaviour is on the GCC bug tracker as PR 77781.

Upvotes: 6

Related Questions