class template specialization with constraint / concept

Viewed 1024

I try to use a constraint for a class specialization:

struct A {};
struct B {};
struct C {};

template<typename T>
concept bool AorB() {
    return std::is_same<T, A>::value || std::is_same<T, B>::value;
}

template<typename T>
class X {};

template<AorB T>
class X {};

int main() {
    X<A> x1; // error: redeclaration 'template<class T> class X' with different constraints class X {};
    X<B> x2;
    X<C> x3;
}

I don't know if I am making a mistake here or if this generally won't be possible?

What could be alternatives to this approach? I could make to specializations using CRTP to a common base template, but thats looks ugly to me.

1 Answers
Related