|
conststr 0.2.1
|
Compile-time reflection for aggregate types. More...
Classes | |
| struct | any_type |
| Type that can be implicitly converted to any type. More... | |
| struct | cptr |
| Wrapper of pointer type. More... | |
Typedefs | |
| template<typename T , std::size_t N> | |
| using | type_of = std::remove_cvref_t< std::tuple_element_t< N, decltype(to_tuple(fake_obj< T >))> > |
Type of N-th member of a default-constructible aggregate type T. More... | |
| template<typename T , conststr::cstr Name> | |
| using | type_of_member = type_of< T, index_of< T, Name > > |
| Get the type of the member by its name. More... | |
Functions | |
| template<typename T , typename... Args> requires (std::is_aggregate_v<std::remove_cvref_t<T>> && std::is_default_constructible_v<std::remove_cvref_t<T>>) | |
| consteval std::size_t | number_of_members_impl () |
Internal implementation of number_of_members. Get The number of a default-constructible aggregate type's members. More... | |
| template<class T , std::size_t N = number_of_members<T>> requires (N <= 128) | |
| constexpr decltype(auto) | to_tuple (T &&t) |
Convert a value of type T to a tuple containing references to all its members. More... | |
| template<typename T , std::size_t N> | |
| consteval auto | cptr_of_member () |
| Get the pointer of the N-th member as a constexpr value. More... | |
| template<cptr Ptr> | |
| consteval auto | pretty_name () |
| Core function to get member name via compiler built-in macro. More... | |
| template<conststr::cstr Name> | |
| consteval auto | basename_of_impl () |
Internal implementation of basename_of. get the Base name of a full qualified name. More... | |
| template<cptr Ptr> | |
| consteval auto | name_of_ptr_impl () |
Internal implementation of name_of_ptr. Extract the real name from the output of pretty_name(). More... | |
| template<typename T , conststr::cstr Name, std::size_t SrchIdx> requires (number_of_members<T> > SrchIdx) | |
| constexpr size_t | index_of_impl () |
Internal implementation of index_of. Get the index of the member by its name. More... | |
| template<std::size_t N, typename T > | |
| constexpr decltype(auto) | member_of (T &&t) |
Get member reference of object t. More... | |
| template<conststr::cstr Name, typename T > requires std::same_as<typename decltype(Name)::value_type, char> | |
| constexpr decltype(auto) | member_of (T &&t) |
Get member reference of object t via member's name. More... | |
Variables | |
| template<typename T > | |
| const T | fake_obj |
An object of T that can be used in constant context without really construct it. More... | |
| template<typename T > | |
| constexpr std::size_t | number_of_members = number_of_members_impl<T>() |
| The number of a default-constructible aggregate type's members. More... | |
| template<conststr::cstr Name> | |
| constexpr auto | basename_of = basename_of_impl<Name>() |
| Base name of a full qualified name. More... | |
| template<cptr Ptr> | |
| constexpr auto | name_of_ptr = name_of_ptr_impl<Ptr>() |
| Get the variable or class member name from its pointer. More... | |
| template<typename T , std::size_t N> | |
| constexpr auto | name_of = name_of_ptr<cptr_of_member<T, N>()> |
Name of N-th member of a default-constructible aggregate type T. More... | |
| template<typename T , conststr::cstr Name> | |
| constexpr size_t | index_of = index_of_impl<T, Name, 0>() |
| Get the index of the member by its name. More... | |
Compile-time reflection for aggregate types.
| using reflect::type_of = typedef std::remove_cvref_t< std::tuple_element_t<N, decltype(to_tuple(fake_obj<T>))> > |
Type of N-th member of a default-constructible aggregate type T.
| T | any default-constructible aggregate type |
| N | index of member |
| using reflect::type_of_member = typedef type_of<T, index_of<T, Name> > |
Get the type of the member by its name.
This is just a simplified API of reflect::type_of<T, reflect::index_of<T, Name>>.
| T | any default-constructible aggregate type |
| Name | name of the member to search |
| consteval auto reflect::basename_of_impl | ( | ) |
Internal implementation of basename_of. get the Base name of a full qualified name.
| Name | string containing a name that may be quailfied |
| consteval auto reflect::cptr_of_member | ( | ) |
Get the pointer of the N-th member as a constexpr value.
| T | any type |
| N | index of the member |
cptr wrapped pointer.
|
constexpr |
Internal implementation of index_of. Get the index of the member by its name.
| T | any default-constructible aggregate type |
| Name | name of the member to search |
| SrchIdx | for recursion only, keep it 0 |
|
constexpr |
Get member reference of object t.
Please use decltype(auto) for deducing the return value type. For example:
| N | index of member |
| T | DO NOT specify it, let it be automatically deduced |
| t | object of type T |
t is a l-value reference. t is a r-value reference.
|
constexpr |
Get member reference of object t via member's name.
Please use decltype(auto) for deducing the return value type. For example:
| Name | name of member |
| T | DO NOT specify it, let it be automatically deduced |
| t | object of type T |
t is a l-value reference. t is a r-value reference. | consteval auto reflect::name_of_ptr_impl | ( | ) |
Internal implementation of name_of_ptr. Extract the real name from the output of pretty_name().
| Ptr | pointer to the the variable or class member you want to reflect. |
| consteval std::size_t reflect::number_of_members_impl | ( | ) |
Internal implementation of number_of_members. Get The number of a default-constructible aggregate type's members.
Just call number_of_members_impl<T>() and keep the template pack Args empty. On how it works, it first tests whether T can be constructed with one parameter, if so, then tries to construct it with two parameters, and so on until T cannot be constructed with N parameters, then the number of members of T is N - 1.
| T | must be a default-constructible aggregate type |
| Args | for recursion only, keep it empty |
| consteval auto reflect::pretty_name | ( | ) |
Core function to get member name via compiler built-in macro.
"consteval auto reflect::pretty_name() [with cptr<...auto...> Ptr = ...]". "auto reflect::pretty_name() [Ptr = ...]". "auto __cdecl reflect::pretty_name<...>(void)". | Ptr | pointer to the the variable or member you want to reflect |
conststr::cstr.
|
constexpr |
Convert a value of type T to a tuple containing references to all its members.
| T | any type. |
| N | number of T's members, automatically calculated if T is a default constructible aggregate type. Otherwise, the caller needs to provide it. |
t's members.
|
constexpr |
Base name of a full qualified name.
For example, basename_of<"xxx::yyy::zzz->nnn"_cs> is "nnn"_cs.
| Name | Name the name that may be quailfied. |
|
extern |
An object of T that can be used in constant context without really construct it.
| T | any type |
|
constexpr |
Get the index of the member by its name.
For example, reflect::index_of<S, "point"> if the type S has a member named point.
| T | any default-constructible aggregate type |
| Name | name of the member to search |
|
constexpr |
Name of N-th member of a default-constructible aggregate type T.
| T | any default-constructible aggregate type |
| N | index of member |
|
constexpr |
Get the variable or class member name from its pointer.
| Ptr | pointer to the the variable or class member you want to reflect. |
Ptr points to an array.
|
constexpr |
The number of a default-constructible aggregate type's members.
| T | must be a default-constructible aggregate type |