Testing for and using named static and non static members of types. More...
Go to the source code of this file.
Classes | |
| struct | ugmisc::default_type< T > |
| struct | static_member_caller< Access, T > |
| struct | member_caller< Access > |
| struct | member_value< Access, CopyValue > |
| struct | member_type_access< Access, T > |
| struct | static_member_value< Access, T > |
Macros | |
| #define | UGMISC_DECL_MEMBER_ACCESS(TNAME, NAME) |
| #define | UGMISC_DECL_STATIC_MEMBER_CALLER(TNAME, NAME) |
| #define | UGMISC_DECL_MEMBER_TYPE_ALIAS(TNAME, NAME) |
| #define | UGMISC_DECL_STATIC_MEMBER_ACCESSOR(TNAME, NAME) |
| #define | UGMISC_NAMED_MEMBER_TYPE_TEST(TEMPLATENAME, ALIASNAME, HASMEMBERNAME, NAME) |
| #define | UGMISC_MEMBER_TYPE_TEST(NAME) |
| #define | UGMISC_NAMED_MEMBER_STATIC_METHOD_CALL(TEMPLATENAME, NAME) |
| #define | UGMISC_MEMBER_STATIC_METHOD_CALL(NAME) |
Enumerations | |
| enum | member_value_copy { MEMBER_COPY_AUTO , MEMBER_COPY_NEVER , MEMBER_COPY_ALWAYS } |
Testing for and using named static and non static members of types.
The utilities provided by this header will be obsoleted by C++26's reflection support. But if that support is not available or can't be assumed, this is a clumsy, horrible substitute.
There are 4 things you can do:
Everything you might want to do with member.hpp has two parts. First there is the macro UGMISC_DECL_MEMBER_ACCESS, which defines a type. This type can be declared at namespace or class scope. The type declared using the UGMISC_DECL_MEMBER_ACCESS macro is responsible for knowing the name of the class member you want to use.
Then there is a template in the ugmisc namespace, which takes that class as its first parameter.
Use the template static_member_caller.
For example:
See static_member_caller for a full explanation, including how to fallback to a default value, or find out if the call would be valid without actually making it.
Use the template member_type_access.
For example, to find the first of X::foo and Y::foo which is a valid type expression:
See member_type_access for full instructions, including how to include a default type, and how to test if the type exists at all.
Use the template static_member_value.
For example, to find a reference to the first of X::foo and Y::foo which is an accessible static member:
See static_member_value for full instructions, including how to provide a default fallback value.
Use the template member_caller.
For example, to find the first of x.foo(1) and y.foo(1) which is valid and obtain the return value:
See member_caller for full instructions, including how to provide a default fallback value.
Use the template member_value.
For example, to find the first of x.foo and y.foo which is valid and obtain a reference:
See member_value for full instructions, including how to provide a default fallback, and notes about how to keep everything constexpr.
| #define UGMISC_DECL_MEMBER_ACCESS | ( | TNAME, | |
| NAME ) |
Declares a type which can be used for named member access of types and objects. Can be passed to the template classes and functions which find member types and references static and non-member objects, and forward arguments to static and non static methods.
TNAME is the name the declared type will have.
NAME is the member name it will access.
| #define UGMISC_DECL_MEMBER_TYPE_ALIAS | ( | TNAME, | |
| NAME ) |
| #define UGMISC_DECL_STATIC_MEMBER_ACCESSOR | ( | TNAME, | |
| NAME ) |
| #define UGMISC_DECL_STATIC_MEMBER_CALLER | ( | TNAME, | |
| NAME ) |
| #define UGMISC_MEMBER_STATIC_METHOD_CALL | ( | NAME | ) |
| #define UGMISC_MEMBER_TYPE_TEST | ( | NAME | ) |
| #define UGMISC_NAMED_MEMBER_STATIC_METHOD_CALL | ( | TEMPLATENAME, | |
| NAME ) |
Non static member access. ::ugmisc
| #define UGMISC_NAMED_MEMBER_TYPE_TEST | ( | TEMPLATENAME, | |
| ALIASNAME, | |||
| HASMEMBERNAME, | |||
| NAME ) |
| enum member_value_copy |
| Enumerator | |
|---|---|
| MEMBER_COPY_AUTO | Default. Copy value if safe and trivial to do so. |
| MEMBER_COPY_NEVER | Always take a reference to the original object. |
| MEMBER_COPY_ALWAYS | Always copy the value. |