PyOPTProblem
PyOPTProblem

Reputation: 75

How do I use partial specializations as template template parameters?

I have a class template taking a template template parameter

template<template<class> typename T>
struct S {};

and a class template taking 2 template parameters

template<size_t i, typename T>
struct A {};

Is there any way to instantiate S with a partial specialization of A over the i parameter, so that I can write the following?

S<A< /*someNumber*/ >> someStruct;

I can create an alias template

template<typename T>
using Inner = A<5, T>;

and instantiate S with it

S<Inner> SInner;

But this only works for the fixed value of 5, because alias templates can't be partially specialized. Is there maybe some way to make Inner a template?

Upvotes: 2

Views: 62

Answers (1)

Jarod42
Jarod42

Reputation: 217075

You might organize your code differently:

template <size_t i>
struct A_outer {
    template <typename T>
    struct A{};
};

S<A_outer<42>::A> s;

Demo

Upvotes: 1

Related Questions