C++ enum of types
I wish to use a collection of types in a variant template
std::variant<type0, type1, type2, ..., typen>.
typen can be anything such as an
std::vector<int> say. Is there a way to abbreviate
type0, type1, type2, ..., typen in a type enum of some sort?? I'm trying not to write
std::variant<type0, type1, type2, ..., typen> every time.
You want a type alias: https://en.cppreference.com/w/cpp/language/type_alias
using short_name = std::variant<type0,type1,type2, ..., typen>;
I could benefit from accessing individual typen later on. So I'd prefer not to alias the variant
Thats no reason to not use a type alias. You can still use
type0etc. And to get the n-th type of the variant there is
static_assert( std::is_same_v< type0, std::variant_alternative_t<0,short_name> > );