morph
0.1.0
Asynchronous bridge between GUI thread and business models
Toggle main menu visibility
Loading...
Searching...
No Matches
reflected_member.hpp
Go to the documentation of this file.
1
// SPDX-License-Identifier: Apache-2.0
2
3
#pragma once
4
5
/// @file detail/reflected_member.hpp
6
/// @brief The value glaze reads and writes under a reflected key.
7
8
#include <cstddef>
9
#include <glaze/glaze.hpp>
10
#include <type_traits>
11
12
namespace
morph::detail {
13
14
/// @brief The value glaze reads and writes under `glz::reflect<T>::keys[I]`.
15
///
16
/// `glz::reflect<T>` follows a `glz::meta<T>` when one exists, and that meta
17
/// may omit, rename, reorder or compute members. `glz::to_tie` always follows
18
/// the aggregate's declaration order. Indexing one with the other's `I` hands
19
/// one member's value to another member's name — a hidden member offered under
20
/// a public key, or a key bound to a value of a different type. This reads the
21
/// value from the same source the key comes from: the declaration-order tie for
22
/// a type glaze reflects by itself, the meta's `I`-th value otherwise.
23
///
24
/// For a member of the object, the result is a reference to it, `const` when
25
/// @p object is. A meta entry that computes its value (a lambda, a glaze
26
/// wrapper such as `glz::quoted_num`) yields whatever glaze's `get_member`
27
/// yields for it, which may be a value rather than a reference.
28
///
29
/// @tparam I Index of the key in `glz::reflect<std::remove_cvref_t<T>>::keys`.
30
/// @tparam T The object's type, possibly `const`-qualified; a type glaze
31
/// reflects by itself or one with a `glz::meta` object.
32
/// @param object The object to read from; it must outlive the returned
33
/// reference.
34
/// @return The value glaze reads and writes under key `I` of @p object.
35
template
<std::
size_t
I,
typename
T>
36
[[nodiscard]]
constexpr
decltype
(
auto
)
reflectedMember
(T&
object
) {
37
using
Plain = std::remove_cv_t<T>;
38
if
constexpr
(glz::reflectable<Plain>) {
39
auto
tie = glz::to_tie(
object
);
40
return
glz::get_member(
object
, glz::get<I>(tie));
41
}
else
{
42
return
glz::get_member(
object
, glz::get<I>(glz::reflect<Plain>::values));
43
}
44
}
45
46
}
// namespace morph::detail
morph::detail::reflectedMember
constexpr decltype(auto) reflectedMember(T &object)
The value glaze reads and writes under glz::reflect<T>::keys[I].
Definition
reflected_member.hpp:36
morph
detail
reflected_member.hpp
Generated by
1.17.0