mpc
Haskell-like feature supports in C++
tagged_union.hpp
Go to the documentation of this file.
1
2#pragma once
3#include <variant>
5
6namespace mpc {
7 template <class T, std::size_t Idx>
8 using nth_element_t = single<T, index_constant<Idx>>;
9
10 namespace detail {
11 template <class, class...>
13
14 template <std::size_t... Idx, class... Args>
15 struct tagged_union_impl<std::index_sequence<Idx...>, Args...> {
16 using type = std::variant<nth_element_t<Args, Idx>...>;
17 };
18 } // namespace detail
19
20 template <class... Args>
21 using tagged_union =
22 typename detail::tagged_union_impl<std::index_sequence_for<Args...>, Args...>::type;
23
24 template <std::size_t Idx, class T>
25 constexpr nth_element_t<T, Idx> make_nth_element(T&& t) {
26 return std::forward<T>(t);
27 }
28} // namespace mpc
Definition: tagged_union.hpp:12
A class that holds a single value.
Definition: single.hpp:15