Lukas Engelke - 1 year ago 104

C++ Question

I have a template that provides a type for any given Order in the range from

`0`

`MaxOrder`

`template <class Graph, int Order> TypeHelper;`

This is necessary because

`TypeHelper<Graph, k>`

`TypeHelper<Graph, 0>`

`TypeHelper<Graph, k - 1>`

`TypeHelper<Graph, k + 1>`

`Graph`

`Payload`

`template <class... Payloads> Graph;`

In order to terminate the recursion at

`TypeHelper<Graph, 0>`

`TypeHelper<Graph, MaxOrder>`

`MaxOrder`

`Payloads...`

One obvious solution is to introduce

`MaxOrder`

`Graph`

As an example:

`template <int MaxOrder, class... Payloads> Graph;`

template <template <int, class...> class Graph, int MaxOrder, class... Payloads>

struct TypeHelper<Graph<MaxOrder, Payloads...>, MaxOrder>

But I would prefer something like this

`template <template <class...> class Graph, class... Payloads>`

struct TypeHelper<Graph<Payloads...>, sizeof...(Payloads)>

But this does not work.

Further reading: Is sizeof... allowed in template arguments for specialization?

Any suggestions?

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

I'm not sure I got the problem, but you can still use an intermediate class that inherits from your actual implementation:

```
template <class Graph, int Order>
struct TypeHelperImpl;
// specializations of TypeHelperImpl
template <typename...>
struct TypeHelper;
template <template <class...> class Graph, class... Payloads>
struct TypeHelper<Graph<Payloads...>, Payloads...>
: TypeHelperImpl<Graph<Payloads...>, sizeof...(Payloads)> {};
```