Duplicate variant types, possible? #843
-
Hello We have a use-case where variant keys can map to the same type and i was hoping to simply extend the put/delete action. eg. `using tagged_variant = std::variant<put_action, delete_action, delete_action>; template <> But this errors with
Is this simply not possible using the variant method or should we move to a custom handler? /Me |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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 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 template <int Alias>
struct glz::meta<base_delete_action<Alias>>
{
// your meta specification here
}; Let me know if this solution is acceptable for you. There are other ways to produce strongly typed aliases as well. Note that with this approach you would make your variant: |
Beta Was this translation helpful? Give feedback.
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.
You can use reflection or partial template specialization on
base_delete_action
so that you don't duplica…