draconisplusplus/include/rfl/internal/define_variant.hpp

47 lines
1.3 KiB
C++
Raw Normal View History

2024-05-31 22:59:00 -04:00
#ifndef RFL_INTERNAL_DEFINEVARIANT_HPP_
#define RFL_INTERNAL_DEFINEVARIANT_HPP_
#include <variant>
namespace rfl {
2024-06-08 14:10:59 -04:00
namespace internal {
/// Allows you to combine several variants.
template <class... Vars>
struct define_variant;
/// Recursive case - both variants.
template <class... Vars1, class... Vars2, class... Tail>
2024-06-08 15:53:06 -04:00
struct define_variant<
std::variant<Vars1...>,
std::variant<Vars2...>,
Tail...> {
using type =
typename define_variant<std::variant<Vars1..., Vars2...>, Tail...>::
type;
2024-06-08 14:10:59 -04:00
};
/// Recursive case - variant plus other type.
template <class... Vars, class Head, class... Tail>
struct define_variant<std::variant<Vars...>, Head, Tail...> {
using type =
typename define_variant<std::variant<Vars..., Head>, Tail...>::type;
};
/// Recursive case - other type.
template <class Head, class... Tail>
struct define_variant<Head, Tail...> {
using type = typename define_variant<std::variant<Head>, Tail...>::type;
};
/// Special case - only a single variant is left.
template <class... Vars>
struct define_variant<std::variant<Vars...>> {
using type = std::variant<Vars...>;
};
} // namespace internal
} // namespace rfl
2024-05-31 22:59:00 -04:00
#endif