8 #include <hilti/rt/exception.h> 9 #include <hilti/rt/extension-points.h> 10 #include <hilti/rt/util.h> 22 template<
int I,
typename U>
29 _u->value.template emplace<I>(t);
35 _u->value.template emplace<I>(std::forward<T>(t));
45 template<
int I,
class T>
46 inline auto&
get(
const T& u) {
48 return std::get<I>(u.value);
49 }
catch (
const std::bad_variant_access& ) {
50 throw UnsetUnionMember(
"access to union member that does not hold value");
54 template<
int I,
class U>
55 inline auto get_proxy(U& u) {
61 template<
typename... T>
72 Union(
const F& t) : value(t){};
74 Union(
const F&& t) : value(t){};
76 Union& operator=(
const F& t) {
82 Union& operator=(F&& t) {
92 auto index()
const {
return value.index(); }
94 std::variant<std::monostate, T...> value;
97 namespace detail::adl {
98 template<typename T, typename std::enable_if_t<std::is_base_of<trait::isUnion, T>::value>* =
nullptr>
99 inline std::string
to_string(
const T& x, adl::tag ) {
100 std::string field =
"<unset>";
102 auto render_one = [&](
auto k,
auto v) {
107 x.__visit(render_one);
std::string to_string(T &&x)
Definition: extension-points.h:26
auto index() const
Definition: union.h:92
std::string fmt(const char *fmt, const Args &... args)
Definition: fmt.h:13