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 int
or 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.
1 answer
-
answered 2022-01-19 16:44
463035818_is_not_a_number
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
type0
etc. And to get the n-th type of the variant there isstd::variant_alternative_t
:static_assert( std::is_same_v< type0, std::variant_alternative_t<0,short_name> > );
How many English words
do you know?
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
how many words do you know
Powered by Examplum