Search code examples
c++templatespartial-specialization

Can i partially specizlize template for not all non-type parameters


template<int, int> 
struct T;

template<> 
struct T<?, ?> {};

i want this to work

typedef T<1, 0> t;

and this to cause compile time error

typedef T<1, 2> t;

EDIT, i mean i want second parameter to be 0. and i can't use C++11 features.


Solution

  • Your quesiton is not too clear. Are you looking for this?

    template <int, int>
    struct T;
    
    template<int x>
    struct T<x, 0>
    {
      // Definition of the struct for the allowed case
    };