I have a template which can be reduced to the following
template <typename T, template <typename U> class Base>
class Derived: Base<T> {
};
As Base
I would like to be able to use a template which may have a non-template parameter. For example
template <unsigned N, typename T>
struct NBase {
};
This obviously won't work directly as its parameters do not match the single parameter of Base
, so I thought I would do something like
template <unsigned S>
struct NAdapter {
template <typename T>
using B = NBase<S, T>;
};
This kind of works, for instance this compiles:
void f() {
Derived<int, NAdapter<100>::B> a;
}
This however doesn't compile
template <unsigned M>
void eval() {
Derived<int, NAdapter<M>::B> b;
}
The resulting error is note: expected a class template, got ‘NAdapter<M>::B’
.
Is there a way to adapt NBase
as Base
so it would work in both cases?
Solution
This works, thank you @mutableVoid for your suggestion!
template <unsigned M>
void eval() {
Derived<int, NAdapter<M>::template B> b;
}