I'm not sure that this is possible, but say I have:
using my_variant = std::variant<Class1, Class2, Class3>;
Now at some point, I create a Class4
and would like to extend my_variant2
to include all of my_variant
along with Class4
(in a general way, i.e. not just using another using...
) so that I can do something like create an array std::array<my_variant2, n>
.
Is this something that can be done?
#include <variant>
template <typename T, typename... Args> struct concatenator;
template <typename... Args0, typename... Args1>
struct concatenator<std::variant<Args0...>, Args1...> {
using type = std::variant<Args0..., Args1...>;
};
int main() {
using type_t = std::variant<int, char, double>;
static_assert(
std::is_same_v<
concatenator<type_t, float, short>::type,
std::variant<int, char, double, float, short>>);
return 0;
}