I have a problem with the static_assert
feature. When I instantiate a class template directly, everything works as expected. But when I pass it as a parameter for the different class template, static_assert
does not work.
template <int X>
class A{
static_assert(X == 0, "X != 0");
};
template <class T>
class B{
};
B<A<1>> b; // Static assert does not work
A<1> a; // error: static assertion failed: X != 0
EDIT
Thanks all for the answers. Is there a way to explicitly instantiate A without creation of A instances / inheriting from A? I was trying this:
template <int X>
class A{
static_assert(X == 0, "X != 0");
};
template <class T>
class B;
template <template <int X> class T, int X>
class B<T<X>>{
template class T<X>;
};
But this is incorrect.
See Question&Answers more detail:os