Closed JasonCoombs closed 2 years ago
Metafunction re-use
The macro encodes only the name of the inner type for which we are searching and the fact that we are introspecting for an inner type within an enclosing type.
Because of this, once we create our metafunction for introspecting an inner type by name, we can reuse the metafunction for introspecting any enclosing type, having any inner type, for that name.
Furthermore since we have only encoded the name of the inner type for which we are introspecting, we can not only introspect for that inner type by name but add different lambda expressions to inspect that inner type for whatever we want to find out about it using the same metafunction.
Introspecting a specific user-defined type
Just as you use tti to look for a general type within some enclosing class, struct, or union, you can also look for a specific user-defined inner type. The only difference in this functionality is that the macros and default names for the generated metafunction change for each specific user-defined type. Otherwise the remaining functionality works exactly the way which was described in the previous topics when looking for a general inner type, including the optional use of an MPL lambda expression if the specific inner type is found.
The specific inner types, their macros, and default generated metafunction names are given in the following table:
As with the general type you can also use the complex macros form of BOOST_TTI_TRAIT_HAS_CLASS(trait,name), BOOST_TTI_TRAIT_HAS_ENUM(trait,name), and BOOST_TTI_TRAIT_HAS_UNION(trait,name) respectively to directly generate the metafunction name.
If you introspect for a specific user-defined type with a given name, and some other type with that given name is found, the metafunction will return the expected value of 'false', but no compiler error will result.
In all other respects using these macros/metafunctions for specific inner user-defined types will work in exactly the same way as has been explained for searching for a general inner type. The specific inner type functionality gives the end-user a finer grained introspection facility than looking for a general type within an enclosing user-defined type.
I'm working on revising the organization of type_traits throughout crypto3 and to illustrate how this makes the code more maintainable and easier to read, consider this discussion for my related pull request:
https://github.com/NilFoundation/crypto3-algebra/pull/73#issuecomment-1046320083
I do agree with this. Merging it in.
https://github.com/NilFoundation/crypto3-pubkey/issues/27#issuecomment-1046118845
I also suggest style improvement from using the
_TRAIT_
variation of BOOST_TTI macros, as in: