repr 0.1
Reconstructable string representations and more
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
variant.h
Go to the documentation of this file.
#pragma once
#include <concepts>
#include <sstream>
#include <string>
#include <type_traits>
#include <variant>
#include "category.h"
namespace librepr {
template <typename T>
struct Reflect;
namespace detail {
template <typename T>
static constexpr bool value = false;
};
template <template <typename...> class Variant, typename... Ts>
requires std::derived_from<Variant<Ts...>, std::variant<Ts...>>
static constexpr bool value = true;
};
template <template <typename...> class Variant, typename... Ts>
requires std::derived_from<Variant<Ts...>, std::variant<Ts...>>
struct VariantDetector<Variant<Ts...>> {
static constexpr bool value = true;
using alternatives = TypeList<Ts...>;
};
} // namespace detail
template <typename T>
template <is_variant T>
struct Reflect<T> : category::Type<T> {
using type = T;
constexpr static bool can_descend = true;
template <typename V>
static void visit(V&& visitor, type& obj) {
[&visitor]<typename U>(U&& alternative) {
},
obj);
}
template <typename V>
static void visit(V&& visitor) {
alternatives::for_each([&visitor]<typename U>() { visitor(Reflect<U>{}); });
}
};
} // namespace librepr