26 operator T() const noexcept;
29template <typename T, std::
size_t... Indices>
30[[nodiscard]] consteval auto isAggregateInitializable(std::index_sequence<Indices...>) noexcept ->
bool
32 return requires { T{(
static_cast<void>(Indices), Any{})...}; };
35template <
typename T, std::
size_t N>
36inline constexpr bool isAggregateInitializableWith = isAggregateInitializable<T>(std::make_index_sequence<N>{});
38template <
typename T, std::
size_t N = 0>
39[[nodiscard]]
consteval auto aggregateFieldCount() noexcept -> std::
size_t
43 static_assert(!isAggregateInitializableWith<T, maxFieldCount + 1>,
44 "orm::reflection supports aggregates with at most 128 fields.");
47 else if constexpr (isAggregateInitializableWith<T, N> && !isAggregateInitializableWith<T, N + 1>)
53 return aggregateFieldCount<T, N + 1>();
58inline constexpr bool supportedAggregateCategory = std::is_aggregate_v<T> && !std::is_union_v<T> && !std::is_array_v<T>;
60template <
typename T,
bool = supportedAggregateCategory<T>>
61struct ReflectionTraits;
64struct ReflectionTraits<T, false>
66 static_assert(std::is_aggregate_v<T>,
"ORM_REFLECTION_AGGREGATE: orm::reflection requires an aggregate type.");
67 static_assert(!std::is_union_v<T>,
"orm::reflection does not support unions.");
68 static_assert(!std::is_array_v<T>,
"orm::reflection does not support raw C arrays.");
70 static constexpr std::size_t count = 0;
71 using Tuple = std::tuple<>;
75struct ReflectionTraits<T, true>
77 static constexpr std::size_t count = aggregateFieldCount<T>();
78 using Binding =
decltype(bindingTraitsImpl(std::declval<T&>(), std::integral_constant<std::size_t, count>{}));
79 using Tuple =
typename Binding::Tuple;
82 template <std::size_t... Indices>
83 [[nodiscard]]
static consteval auto containsRawArray(std::index_sequence<Indices...>)
noexcept ->
bool
85 return (std::is_array_v<std::remove_reference_t<std::tuple_element_t<Indices, Tuple>>> || ... ||
false);
89 static_assert(Binding::fieldsAreAddressable,
90 "ORM_REFLECTION_BIT_FIELD: orm::reflection does not support bit-fields.");
91 static_assert(std::tuple_size_v<Tuple> == count,
92 "orm::reflection cannot decompose this aggregate; inheritance is not supported.");
93 static_assert(!containsRawArray(std::make_index_sequence<count>{}),
94 "orm::reflection does not support raw C-array fields; use std::array instead.");
98using ReflectedType = std::remove_cv_t<std::remove_reference_t<T>>;
101inline constexpr InactiveStorage<InactiveStorage<T>> fakeObjectStorage{};
104[[nodiscard]]
consteval auto fakeObject() noexcept -> const T&
106 return fakeObjectStorage<T>.object.object;
112 template <
typename T>
113 inline constexpr std::size_t
fieldCount = detail::ReflectionTraits<detail::ReflectedType<T>>::count;
115 template <
typename T>
116 [[nodiscard]]
constexpr auto tieFields(T & value)
noexcept
119 using Type = detail::ReflectedType<T>;
120 return detail::tieFieldsImpl(value, std::integral_constant<std::size_t,
fieldCount<Type>>{});
123 template <
typename T>
124 [[nodiscard]]
constexpr auto tieFields(
const T& value)
noexcept
126 using Type = detail::ReflectedType<T>;
127 return detail::tieFieldsImpl(value, std::integral_constant<std::size_t,
fieldCount<Type>>{});
130 template <
typename T>
135 template <
typename T>
136 [[nodiscard]]
constexpr auto fieldPointers(T & value)
noexcept
139 return std::apply([]<
typename... Fields>(Fields&...
fields) {
return std::tuple{std::addressof(
fields)...}; },
143 template <
typename T>
144 [[nodiscard]]
constexpr auto fieldPointers(
const T& value)
noexcept
146 return std::apply([]<
typename... Fields>(
const Fields&...
fields)
150 template <
typename T>
158 template <
typename T, std::
size_t Index>
160 std::tuple_element_t<Index, typename detail::ReflectionTraits<detail::ReflectedType<T>>::Tuple>>;