I want to have something like:
template <typename... Ts>
using make_variant_t = /* ??? */;
such that, for instance, make_variant_t<Foo, Bar>
evaluates as the type
std::variant<Foo, std::vector<Foo>, Bar, std::vector<Bar>>
in that order. How, if it is possible, can this be achieved?
With Boost.Mp11 this is a short, one-liner (as always):
template <typename... Ts>
using make_variant_t = mp_append<variant<Ts, vector<Ts>>...>;
make_variant_t<int, char>
will first produce two variants, variant<int, vector<int>>
and variant<char, vector<char>>
. Those each are "lists" in the Mp11 sense, and mp_append
takes a bunch of lists and concatenates them together, producing variant<int, vector<int>, char, vector<char>>
as desired. Demo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With