Skip to content

Duplicate variant types, possible? #843

Answered by stephenberry
Dikymon asked this question in Q&A
Discussion options

You must be logged in to vote

It's not a good idea to duplicate a type in a std::variant. So, what you're wanting is two names to refer to the same type. This is currently not supported, as it would add complexity to the code.

However, you can make a strongly typed alias to your type.

Note that using delete_action2 = delete_action; does not work because it is still the same type.

To get a different type you need to make a base type that is templated.

template <int Alias>
struct base_delete_action
{
   // put fields here
};

using delete_action = base_delete_action<1>;

using delete_action2 = base_delete_action<2>;

You can use reflection or partial template specialization on base_delete_action so that you don't duplica…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by stephenberry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants