repr 0.1
Reconstructable string representations and more
Loading...
Searching...
No Matches
variant.h
Go to the documentation of this file.
1#pragma once
2#include <concepts>
3#include <sstream>
4#include <string>
5#include <type_traits>
6#include <variant>
7
8#include <librepr/name/type.h>
9
12
13#include "category.h"
14
15namespace librepr {
16template <typename T>
17struct Reflect;
18
19namespace detail {
20template <typename T>
22 static constexpr bool value = false;
23};
24
25template <template <typename...> class Variant, typename... Ts>
26 requires std::derived_from<Variant<Ts...>, std::variant<Ts...>>
28 static constexpr bool value = true;
30};
31
32template <template <typename...> class Variant, typename... Ts>
33 requires std::derived_from<Variant<Ts...>, std::variant<Ts...>>
35 static constexpr bool value = true;
37};
38
39} // namespace detail
40
41template <typename T>
43
44template <is_variant T>
45struct Reflect<T> : category::Type<T> {
46 using type = T;
48 constexpr static bool can_descend = true;
49
50 template <typename V>
51 static void visit(V&& visitor, type& obj) {
53 [&visitor]<typename U>(U&& alternative) {
56 },
57 obj);
58 }
59
60 template <typename V>
61 static void visit(V&& visitor) {
62 alternatives::for_each([&visitor]<typename U>() { visitor(Reflect<U>{}); });
63 }
64};
65
66} // namespace librepr
Definition variant.h:42
Definition ctvi/ctvi.h:9
std::string code_for()
Definition repr:39
Reflect(T &) -> Reflect< T >
T type
Definition aggregate.h:55
static void visit(V &&visitor)
Definition variant.h:61
typename detail::VariantDetector< T >::alternatives alternatives
Definition variant.h:47
static void visit(V &&visitor, type &obj)
Definition variant.h:51
Definition reflection/reflect.h:16
Definition list.h:64
Definition category.h:49
typename TypeList< Ts... >::template map< std::add_const_t > alternatives
Definition variant.h:29
Definition variant.h:21
static constexpr bool value
Definition variant.h:22
T visit(T... args)