repr 0.1
Reconstructable string representations and more
Loading...
Searching...
No Matches
aggregate.h
Go to the documentation of this file.
1#pragma once
2#include <cstddef>
3#include <string>
4#include <string_view>
5#include <type_traits>
6
10#include <librepr/name/member.h>
11
12// TODO
15
16#include "category.h"
17#include "detail/arity.h"
18#include "detail/to_reftuple.h"
19
20namespace librepr {
21
22template <typename T>
24
25template <typename T>
26struct Reflect;
27
28namespace category {
29
30template <typename Member, typename Parent, std::size_t Index>
32 using descend = Member;
33 using type = typename Member::type;
34 using parent = Parent;
35 using parent_type = typename Parent::type;
36
40
41 using Member::visit;
42};
43
44} // namespace category
45
46template <typename T>
47 requires(std::is_aggregate_v<T> && !(std::is_array_v<T> || has_custom_members<T> || detail::has_repr_member<T>))
48struct Reflect<T> : category::Type<T> {
49 constexpr static auto member_count = librepr::detail::arity<T>;
50
51 using member_tuple = decltype(librepr::detail::to_reftuple(std::declval<T>()));
52 static_assert(!std::is_same_v<member_tuple, void>, "Aggregate reflection failed");
53
55 using type = T;
56 using members = typename member_types::template map<librepr::Reflect>;
57 constexpr static bool can_descend = true;
58
59 template <typename V>
60 static void visit(V&& visitor, T& obj) {
62 static_assert(members::size == decltype(decomposed)::size,
63 "Decomposed obj does not match reflected member amount.");
64
65 members::enumerate([&visitor, &decomposed]<typename M, std::size_t Index> {
67 });
68 }
69
70 template <typename V>
71 static void visit(V&& visitor) {
72 members::enumerate(
74 }
75};
76} // namespace librepr
Definition aggregate.h:23
auto to_reftuple(T &&object)
Definition to_reftuple.h:12
typename detail::ReBoxImpl< T, To >::type rebox
Definition pack.h:90
Definition ctvi/ctvi.h:9
std::string code_for()
Definition repr:39
Definition members.h:68
typename accessor::type type
Definition members.h:70
T type
Definition aggregate.h:55
static void visit(V &&visitor)
Definition aggregate.h:71
decltype(librepr::detail::to_reftuple(std::declval< T >())) member_tuple
Definition aggregate.h:51
typename pack::rebox< member_tuple, TypeList >::template map< std::remove_reference_t > member_types
Definition aggregate.h:54
typename member_types::template map< librepr::Reflect > members
Definition aggregate.h:56
static void visit(V &&visitor, T &obj)
Definition aggregate.h:60
Definition reflection/reflect.h:16
Definition customization.h:12
Definition aggregate.h:31
typename Parent::type parent_type
Definition aggregate.h:35
std::string_view name() const
Definition aggregate.h:37
typename Member::type type
Definition aggregate.h:33
Parent parent
Definition aggregate.h:34
Definition category.h:82
Definition category.h:49