Consider a alias template declaration, depending on a single template parameter that can have a finite number of values, like a class enum.
I would like to a employ using to define a type alias for every value of the class enum.
One way of implementing is to use std::conditional:
class enum color { white, red, blue };
struct A {};
struct B {};
struct C {};
template <color c>
using data = std::conditional_t<c == color::white, A, std::conditional_t<c == color::red, B, C>>;
Obviously, when the class enum color is expanded to new values, one needs an additional nested std::conditional, which is rather cumbersome.
I am looking for a solution to express this in a "scalable" way, that is, such that on expanding the class enum one has to do a minimal work.
Something like
template <class c>
using data = some_struct<c, A, B, C>;
where some_struct "select" the type A, B, C depending on the first parameter c.
How can I implement that (in a scalable way)?
A,BandC, and if you add a value then you add aD? Or is it any 3 type? I am not sure if thesome_structis what you want to have, or just your attempt to get thedata?struct D, such thatdata<x> = D.