|
GMP 0.3.0
Generative Metaprogramming library for C++
|
Compile-time enum, aggregate, type-name, and payload-size reflection utilities. More...
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 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 > | |
| 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 , typename F > requires std::is_aggregate_v<std::remove_cvref_t<T>> | |
| void | gmp::for_each_member (T &&value, F &&func) noexcept |
| Visit each member of an aggregate object together with its member 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. | |
| #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. |
| E | The enumeration type to cast into. |
| name | The enumerator name to search for. |
Definition at line 361 of file meta.hpp.
References 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 201 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 317 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 342 of file meta.hpp.
References gmp::enum_values().
| 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 235 of file meta.hpp.
References gmp::enum_values().
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 291 of file meta.hpp.
References gmp::enum_values().
| 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 155 of file meta.hpp.
References gmp::enum_values().
Referenced by gmp::object_factory< AbstractProduct, ConstructorArgs >::create(), gmp::object_factory< AbstractProduct, ConstructorArgs >::create_shared(), gmp::object_factory< AbstractProduct, ConstructorArgs >::create_unique(), gmp::enum_cast(), gmp::enum_count(), gmp::enum_entries(), gmp::enum_index(), gmp::enum_name(), gmp::enum_names(), gmp::enum_values(), gmp::fixed_string< N >::find(), gmp::fixed_string< N >::fixed_string(), gmp::fixed_string< N >::fixed_string(), gmp::for_each_member(), gmp::singleton< T, false >::instance(), gmp::singleton< T, true >::instance(), gmp::is_equal(), gmp::make_named_operator(), gmp::member_count(), gmp::member_name(), gmp::member_names(), gmp::member_ref(), 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::object_factory< AbstractProduct, ConstructorArgs >::register_type< T >::register_type(), gmp::remove_all(), gmp::fixed_string< N >::substr(), gmp::type_name(), and gmp::object_factory< AbstractProduct, ConstructorArgs >::unregister_type().
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 697 of file meta.hpp.
References gmp::constant_arg, and gmp::enum_values().
| consteval int gmp::member_count | ( | ) |
| T | The aggregate type to count members for. |
| Args | The accumulated parameter types for construction testing. |
Definition at line 402 of file meta.hpp.
References gmp::enum_values(), and gmp::member_count().
Referenced by gmp::member_count().
|
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 467 of file meta.hpp.
References gmp::constant_arg, and gmp::enum_values().
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 538 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 645 of file meta.hpp.
References gmp::constant_arg, and gmp::enum_values().
| T | - The aggregate type to introspect (struct/class with public 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::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 81 of file type_size.hpp.