|
GMP 0.4.0
Generative Metaprogramming library for C++
|
Compile-time enum, aggregate, type-name, and payload-size reflection utilities. More...
Concepts | |
| concept | gmp::reflectable |
| Constraint for aggregate types supported by the reflection helpers. | |
Classes | |
| struct | gmp::enum_traits< E > |
| Customize the reflection range or explicit values for an enumeration. More... | |
| struct | gmp::pretty_type_name< T > |
| Format a type name for documentation-friendly display. More... | |
| struct | gmp::pretty_type_name< std::string > |
Formatter specialization for std::string. More... | |
| struct | gmp::pretty_type_name< std::string_view > |
Formatter specialization for std::string_view. More... | |
| struct | gmp::pretty_type_name< std::vector< T > > |
Formatter specialization for std::vector<T>. More... | |
| struct | gmp::pretty_type_name< std::array< T, N > > |
Formatter specialization for std::array<T, N>. More... | |
Macros | |
| #define | GMP_ENUM_RANGE(Enum, Min, Max) |
Specialize gmp::enum_traits with an explicit scan range. | |
| #define | GMP_ENUM_VALUES(Enum, ...) |
Specialize gmp::enum_traits with an explicit enumerator list. | |
Typedefs | |
| template<std::size_t I, typename T > | |
| using | gmp::member_type_t = std::remove_cvref_t< decltype(*detail::field_getter< I, T >(constant_arg< member_count< T >()>))> |
| Alias for the type of the I-th member of an aggregate type. | |
Functions | |
| template<typename E , fixed_string P = type_name<E>() + fixed_string("::")> | |
| consteval auto | gmp::enum_values () |
| Get all enumerator values of an enumeration type at compile-time. | |
| template<typename E , fixed_string P = type_name<E>() + fixed_string("::")> | |
| consteval auto | gmp::enum_count () |
| Count the number of enumerators in an enumeration type at compile-time. | |
| template<auto E, fixed_string P = fixed_string("::")> | |
| consteval auto | gmp::enum_name () |
| Get the name of an enumerator at compile-time. | |
| template<typename E > | |
| consteval auto | gmp::enum_names () |
| Get all enumerator names of an enumeration type at compile-time. | |
| template<typename E > | |
| consteval auto | gmp::enum_entries () |
| Get all enumerator entries (value, name) of an enumeration type at compile-time. | |
| template<typename E > | |
| constexpr auto | gmp::enum_index (E value) -> std::optional< std::size_t > |
| Get the index of an enumerator value in enum_values<E>(). | |
| template<typename E > | |
| constexpr auto | gmp::enum_cast (std::string_view name) -> std::optional< E > |
| Cast an enumerator name to its corresponding enumerator value. | |
| template<typename E > requires std::is_enum_v<E> | |
| constexpr auto | gmp::enum_underlying (E value) noexcept -> std::underlying_type_t< E > |
| Return the underlying integer value of an enumerator. | |
| template<typename E > requires std::is_enum_v<E> | |
| constexpr bool | gmp::enum_contains (E value) |
| Test whether an enumerator is present in the reflected set. | |
| template<typename E , typename U > requires std::is_enum_v<E> && std::is_integral_v<U> | |
| constexpr bool | gmp::enum_contains (U value) |
| Test whether an underlying integer value is a reflected enumerator. | |
| template<typename T , typename... Args> requires std::is_aggregate_v<std::remove_cvref_t<T>> | |
| consteval int | gmp::member_count () |
| Count the number of members in an aggregate type at compile-time. | |
| template<std::size_t I, typename T > requires std::is_aggregate_v<T> && (I < member_count<T>()) && (member_count<T>() <= GMP_MAX_SUPPORTED_FIELDS) | |
| consteval auto | gmp::member_name () noexcept |
| Get the name of a specific member of an aggregate type at compile-time. | |
| template<typename T > | |
| consteval auto | gmp::member_names () |
| Get all member names of an aggregate type at compile-time. | |
| template<typename T > requires reflectable<T> | |
| constexpr auto | gmp::member_index (std::string_view name) -> std::optional< std::size_t > |
| Find a reflected member by name. | |
| template<typename T > requires reflectable<T> | |
| constexpr bool | gmp::has_member (std::string_view name) |
| Test whether an aggregate has a reflected member with the given name. | |
| template<typename T > | |
| constexpr auto | gmp::member_type_names () |
| Returns an array of string_view containing the type names of all members of aggregate type T. | |
| template<std::size_t I, typename T , typename UnqualifiedT = std::remove_cvref_t<T>> requires std::is_aggregate_v<UnqualifiedT> && (I < member_count<UnqualifiedT>()) && (member_count<UnqualifiedT>() <= GMP_MAX_SUPPORTED_FIELDS) | |
| decltype(auto) | gmp::member_ref (T &&value) noexcept |
| Get a reference to the I-th member of an aggregate object. | |
| template<typename T > requires reflectable<T> | |
| constexpr auto | gmp::tie_members (T &value) noexcept |
| Return a tuple of references to all members of an aggregate. | |
| template<typename T , typename F > requires reflectable<T> | |
| constexpr decltype(auto) | gmp::apply_members (T &value, F &&func) noexcept(noexcept(std::apply(std::forward< F >(func), tie_members(value)))) |
| Invoke a callable with all aggregate members as separate arguments. | |
| template<typename T , typename F > requires reflectable<T> | |
| constexpr void | gmp::for_each_member (T &&value, F &&func) noexcept(noexcept(detail::for_each_member_impl(std::forward< T >(value), std::forward< F >(func), std::make_index_sequence< member_count_v< std::remove_cvref_t< T > > >{}))) |
| Visit each member of an aggregate object together with its member name. | |
| template<typename T , typename F > requires reflectable<T> | |
| constexpr bool | gmp::visit_member (T &&value, std::string_view name, F &&func) |
| Visit a member selected by name. | |
| template<typename T > | |
| consteval auto | gmp::type_name () |
| Get the string representation of a type at compile-time. | |
| template<typename T > | |
| consteval std::size_t | gmp::type_size () |
| Calculate the actual payload size of a type without aggregate padding. | |
Variables | |
| template<typename E > | |
| constexpr int | gmp::enum_min_v |
The minimum reflection scan value for enumeration type E. | |
| template<typename E > | |
| constexpr int | gmp::enum_max_v |
The maximum reflection scan value for enumeration type E. | |
| template<typename T > | |
| constexpr auto | gmp::member_count_v |
| Number of members in an aggregate type as an inline constant. | |
| #define GMP_ENUM_RANGE | ( | Enum, | |
| Min, | |||
| Max | |||
| ) |
This macro defines enum_traits<Enum>::min and enum_traits<Enum>::max, allowing enum reflection to scan a narrower or wider range than the default.
| Enum | The enumeration type to customize. |
| Min | The minimum integer value to scan. |
| Max | The maximum integer value to scan. |
| #define GMP_ENUM_VALUES | ( | Enum, | |
| ... | |||
| ) |
| gmp::member_type_t |
| I | Zero-based member index. |
| T | The aggregate type to introspect. |
Definition at line 798 of file meta.hpp.
References gmp::enum_values(), and gmp::tie_members().
| E | The enumeration type to cast into. |
| name | The enumerator name to search for. |
Definition at line 399 of file meta.hpp.
References gmp::enum_values(), and gmp::name.
Definition at line 423 of file meta.hpp.
References gmp::enum_index().
Definition at line 432 of file meta.hpp.
References gmp::enum_underlying(), and gmp::enum_values().
| E | The enumeration type to count enumerators for. |
| P | The prefix string used to identify enumerator names (defaults to type name + "::"). |
Definition at line 239 of file meta.hpp.
References gmp::enum_values().
This function returns a compile-time array of (value, name) pairs for all reflected enumerators of E.
| E | The enumeration type to inspect. |
std::array<std::pair<E, std::string_view>, N> containing all reflected enumerators in declaration order. Definition at line 355 of file meta.hpp.
References gmp::enum_values().
| E | The enumeration type of the value being searched. |
| value | The enumerator value to locate. |
Definition at line 380 of file meta.hpp.
References gmp::enum_values().
Referenced by gmp::enum_contains().
| consteval auto gmp::enum_name | ( | ) |
| E | The enumerator value to get the name for. |
| P | The prefix string to remove from the full name (defaults to type name + "::"). |
Definition at line 273 of file meta.hpp.
References gmp::enum_values(), and gmp::name.
This function returns an array containing the names of all enumerators in the enumeration type E.
| E | The enumeration type to get enumerator names for. |
Definition at line 329 of file meta.hpp.
References gmp::enum_values().
Definition at line 414 of file meta.hpp.
Referenced by gmp::enum_contains().
| consteval auto gmp::enum_values | ( | ) |
This function returns the full reflected enumerator set for E. If enum_traits<E>::values is provided, that explicit list is used. Otherwise, the function scans the integer range defined by enum_traits<E>::min and enum_traits<E>::max.
| E | The enumeration type to inspect. |
| P | The expected enumerator-name prefix used during range scanning. |
std::array containing all reflected enumerator values.Definition at line 193 of file meta.hpp.
References gmp::enum_values().
Referenced by gmp::serialization_field< Member, Wire, Transient, Default, Aliases >::alias(), gmp::apply_members(), gmp::basic_serializer< Writer >::array(), gmp::basic_serializer< Writer >::begin_array(), gmp::basic_serializer< Writer >::begin_object(), gmp::object_factory< AbstractProduct, ConstructorArgs >::create(), gmp::object_factory< AbstractProduct, ConstructorArgs >::create_shared(), gmp::object_factory< AbstractProduct, ConstructorArgs >::create_unique(), gmp::basic_deserializer< Reader >::decode(), gmp::serialization_field< Member, Wire, Transient, Default, Aliases >::default_with(), gmp::serialization_field< Member, Wire, Transient, Default, Aliases >::defaulted(), gmp::define_schema(), gmp::serialization_error::describe(), gmp::basic_serializer< Writer >::array_archive::element(), gmp::value_reader::element(), gmp::enum_cast(), gmp::enum_contains(), gmp::enum_count(), gmp::enum_entries(), gmp::enum_index(), gmp::enum_name(), gmp::enum_names(), gmp::enum_values(), gmp::basic_serializer< Writer >::object_archive::field(), gmp::fixed_string< N >::find(), gmp::value_writer::finish(), gmp::fixed_string< N >::fixed_string(), gmp::fixed_string< N >::fixed_string(), gmp::has_member(), gmp::singleton< T, false >::instance(), gmp::singleton< T, true >::instance(), gmp::is_equal(), gmp::serialization_field< Member, Wire, Transient, Default, Aliases >::make_default(), gmp::make_named_operator(), gmp::serialization_field< Member, Wire, Transient, Default, Aliases >::matches(), gmp::value_reader::member(), gmp::member_count(), gmp::member_index(), gmp::member_name(), gmp::member_names(), gmp::member_ref(), gmp::serialization_field< Member, Wire, Transient, Default, Aliases >::name(), gmp::serialization_field< Member, Wire, Transient, Default, Aliases >::names_unique(), gmp::basic_serializer< Writer >::object(), gmp::pretty_type_name< T >::operator()(), gmp::pretty_type_name< std::vector< T > >::operator()(), gmp::pretty_type_name< std::array< T, N > >::operator()(), gmp::operator+(), gmp::fixed_string< N >::operator[](), gmp::serialization_field< Member, Wire, Transient, Default, Aliases >::overlaps(), gmp::prepend_serialization_path(), gmp::object_factory< AbstractProduct, ConstructorArgs >::register_type< T >::register_type(), gmp::object_factory< AbstractProduct, ConstructorArgs >::registered_keys(), gmp::remove_all(), gmp::serialization_value::source_offset(), gmp::fixed_string< N >::substr(), gmp::tie_members(), gmp::serialization_field< Member, Wire, Transient, Default, Aliases >::transient(), gmp::object_factory< AbstractProduct, ConstructorArgs >::try_create_shared(), gmp::object_factory< AbstractProduct, ConstructorArgs >::try_create_unique(), gmp::type_name(), gmp::visit_member(), gmp::basic_serializer< Writer >::write_bool(), gmp::value_writer::write_bool(), gmp::basic_serializer< Writer >::write_floating(), gmp::value_writer::write_floating(), gmp::basic_serializer< Writer >::write_key(), gmp::basic_serializer< Writer >::write_signed(), gmp::value_writer::write_signed(), gmp::basic_serializer< Writer >::write_string(), gmp::value_writer::write_string(), gmp::basic_serializer< Writer >::write_unsigned(), and gmp::value_writer::write_unsigned().
func is invoked once per member in declaration order. Each invocation receives the member name as std::string_view and the corresponding member reference.
| T | The aggregate object type. |
| F | The callable visitor type. |
| value | The aggregate object to inspect. |
| func | The visitor invoked for each member. |
Definition at line 842 of file meta.hpp.
Referenced by gmp::visit_member().
|
constexpr |
Definition at line 666 of file meta.hpp.
References gmp::enum_values(), and gmp::name.
| consteval int gmp::member_count | ( | ) |
| T | The aggregate type to count members for. |
| Args | The accumulated parameter types for construction testing. |
Definition at line 473 of file meta.hpp.
References gmp::enum_values(), and gmp::member_count().
Referenced by gmp::member_count().
|
constexpr |
Definition at line 651 of file meta.hpp.
References gmp::enum_values(), and gmp::name.
|
noexcept |
| I | The zero-based index of the member to get the name for. |
| T | The aggregate type containing the member. |
| Compile-time | error if any of the above requirements are not met. |
Definition at line 558 of file meta.hpp.
References gmp::constant_arg, gmp::enum_values(), and gmp::name.
This function returns an array containing the names of all members of the aggregate type T.
| T | The aggregate type to get member names for. |
Definition at line 632 of file meta.hpp.
References gmp::enum_values().
|
noexcept |
This function returns the selected member while preserving the value category of the aggregate object passed in.
| I | The zero-based member index. |
| T | The aggregate object type. |
| UnqualifiedT | The cvref-stripped aggregate type. |
| value | The aggregate object whose member is requested. |
Definition at line 763 of file meta.hpp.
References gmp::constant_arg, and gmp::enum_values().
| T | - The aggregate type to introspect (struct/class with public members) |
|
constexprnoexcept |
Definition at line 784 of file meta.hpp.
References gmp::enum_values().
Referenced by gmp::apply_members().
This function returns a compile-time string representing the name of the given type T. The implementation is compiler-specific and extracts the type name from compiler-generated function signatures.
| T | The type whose name is to be retrieved. |
Definition at line 53 of file type_name.hpp.
References gmp::enum_values(), gmp::name, gmp::remove_all(), and gmp::fixed_string< N >::size().
For aggregate types, this function sums the sizes of members in declaration order and does not count padding bytes inserted between members or after the final member. Nested aggregate members and bounded array types are calculated recursively. Non-aggregate leaf types use sizeof(T).
| T | The type to calculate. |
Definition at line 82 of file type_size.hpp.
The callable must accept every possible member type of T. It is invoked once when name matches a reflected member.
Definition at line 878 of file meta.hpp.
References gmp::enum_values(), gmp::for_each_member(), and gmp::name.