### BOOST_TTI_HAS_TYPE Usage Examples Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/has__type_8hpp_1ac72dd7b5ac8b0393899641fd745da085 Demonstrates practical usage of the BOOST_TTI_HAS_TYPE macro including basic type detection, MPL lambda expression filtering, and type equivalence checking using boost::is_same. ```cpp // Generate metafunction has_type_MyType in current scope BOOST_TTI_HAS_TYPE(MyType) // Check if MyType is an inner type of EnclosingType has_type_MyType::value // Check with MPL lambda expression has_type_MyType::value // Check if inner type matches another type has_type_MyType >::value ``` -------------------------------- ### BOOST_TTI_HAS_CLASS Usage Examples Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/has__class_8hpp_1acad380feb01ef67e4386946bea71ec33 Examples demonstrating how to use the BOOST_TTI_HAS_CLASS macro to check for the existence of inner types and to apply additional checks using MPL lambda expressions, such as type comparison. ```cpp // Generates metafunction 'has_class_MyType' to find inner class/struct named MyType BOOST_TTI_HAS_CLASS(MyType) // Check if 'MyType' exists in 'EnclosingType' has_class_MyType::value // Check if 'MyType' exists in 'EnclosingType' and satisfies ALambdaExpression has_class_MyType::value // Check if 'MyType' exists in 'EnclosingType' and is the same type as 'SomeOtherType' has_class_MyType>::value ``` -------------------------------- ### Complete Example: Metafunction Generation and Type Introspection Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_detail_has_template/tti_detail_has_template_metafunction Comprehensive example demonstrating metafunction generation for multiple inner class templates using both variadic and non-variadic syntax, definition of user-defined types with various template parameters, and invocation of metafunctions to detect template presence at compile time. ```cpp #include // Using variadic macro, `template type parameters` BOOST_TTI_HAS_TEMPLATE(Template1) BOOST_TTI_HAS_TEMPLATE(Template2) BOOST_TTI_HAS_TEMPLATE(Template3) BOOST_TTI_HAS_TEMPLATE(Template4) BOOST_TTI_HAS_TEMPLATE(Template5) // or using non-variadic macro, `template type parameters` BOOST_TTI_HAS_TEMPLATE(Template1,BOOST_PP_NIL) BOOST_TTI_HAS_TEMPLATE(Template2,BOOST_PP_NIL) BOOST_TTI_HAS_TEMPLATE(Template3,BOOST_PP_NIL) BOOST_TTI_HAS_TEMPLATE(Template4,BOOST_PP_NIL) BOOST_TTI_HAS_TEMPLATE(Template5,BOOST_PP_NIL) // Using variadic macro, `specific parameters` BOOST_TTI_HAS_TEMPLATE(Template6,class,int) BOOST_TTI_HAS_TEMPLATE(Template7,typename,template struct,long) BOOST_TTI_HAS_TEMPLATE(Template8,double,typename) BOOST_TTI_HAS_TEMPLATE(Template9,typename,class,typename,class,typename,short) // or using non-variadic macro, `specific parameters` BOOST_TTI_HAS_TEMPLATE(Template6,(2,(class,int))) BOOST_TTI_HAS_TEMPLATE(Template7,(4,(typename,template struct,long))) BOOST_TTI_HAS_TEMPLATE(Template8,(2,(double,typename))) BOOST_TTI_HAS_TEMPLATE(Template9,(6,(typename,class,typename,class,typename,short))) struct Top { template struct Template1 { }; template class Template2 { }; template class Template3 { }; }; struct Top2 { template class Template3 { }; template struct Template4 { }; template class Template5 { }; }; struct Top3 { template struct Template6 { }; template struct B,long C> class Template7 { }; }; struct Top4 { template struct Template8 { }; template class Template9 { }; }; has_template_Template1::value; // true has_template_Template1::value; // false has_template_Template2::value; // true has_template_Template2::value; // false has_template_Template3::value; // false, not all typename/class template parameters has_template_Template3::value; // true has_template_Template4::value; // false has_template_Template4::value; // true has_template_Template5::value; // false has_template_Template5::value; // true has_template_Template6::value; // true has_template_Template6::value; // false has_template_Template7::value; // true has_template_Template7::value; // false has_template_Template8::value; // false has_template_Template8::value; // true has_template_Template9::value; // false has_template_Template9::value; // true ``` -------------------------------- ### BOOST_TTI_TRAIT_HAS_TEMPLATE Example with Custom Template Parameters Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/has__template_8hpp_1a73e5a57a50d1822c375124ddb779e960 Example showing how to search for an inner class template with specific template parameters including class types, integral types, and template template parameters. Demonstrates both variadic and non-variadic forms using Boost PP arrays. ```C++ // Search for an inner class template called 'MyTemplate', with template parameters // of 'class T,int x,template class U', nested within the class 'MyClass' // using a metafunction name of 'MyMeta'. BOOST_TTI_TRAIT_HAS_TEMPLATE(MyMeta,MyTemplate,class,int,template class) // or BOOST_TTI_TRAIT_HAS_TEMPLATE(MyMeta,MyTemplate,(3,(class,int,template class))) // Non-variadic macro form // Usage: MyMeta::value // compile time boolean constant (true or false) ``` -------------------------------- ### Examples: Generating and Invoking Metafunctions for Static Member Functions Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_detail_has_static_member_function This example showcases the practical application of the BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION macro. It includes generating metafunctions for different static member function names, defining user-defined types with static member functions, and finally invoking the metafunctions with various signatures to check for their existence at compile time. ```cpp #include #include #include // Generate metafunctions BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION(function1) BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION(function2) BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION(function3) // User-defined types for introspection struct AClass { }; struct Top { static int function1(); static AClass function2(double,short *); }; struct Top2 { static long function2(Top &,int,bool,short,float); static Top * function3(long,int,AClass &); }; // Invoking metafunctions and checking values // Example 1: function1 in Top static_assert(has_static_member_function_function1::value, "function1 in Top (int) failed"); static_assert(has_static_member_function_function1::value, "function1 in Top (int ()) failed"); static_assert(!has_static_member_function_function1::value, "function1 in Top2 (int) failed"); // Example 2: function2 in Top static_assert(has_static_member_function_function2 >::value, "function2 in Top (AClass, double, short *) failed"); static_assert(!has_static_member_function_function2 >::value, "function2 in Top2 (AClass, double, short *) failed"); static_assert(has_static_member_function_function2::value, "function2 in Top2 (long (Top&, int, bool, short, float)) failed"); // Example 3: function3 in Top2 static_assert(!has_static_member_function_function3::value, "function3 in Top2 (int ()) failed"); static_assert(has_static_member_function_function3::value, "function3 in Top2 (Top* (long, int, AClass&)) failed"); ``` -------------------------------- ### Define Hypothetical User-Defined Type for Metafunction Examples Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_usingMM This C++ code defines a sample struct 'AType' containing various nested elements such as typedefs, classes, structs, enumerations, unions, templates, data members, and functions. This serves as a model type 'T' for demonstrating compile-time metaprogramming checks using Boost.TTI metafunctions. ```cpp struct AType { // Type typedef int AnIntType; // as a typedef // Class/Struct struct BType // as a nested struct { struct CType { }; }; class AClass // as a nested class { }; // Enumeration enum EColor // as a nested enumeration { Red, Blue, Green }; // Union union AUnion // as a nested union { int i; long l; }; // Class Template template struct AMemberTemplate { }; template struct AnotherMemberTemplate { }; template class,class,long> struct ManyParameters { }; template class,class> struct MoreParameters { }; // Data BType IntBT; // Function int IntFunction(short) { return 0; } // Const Function long AnotherFunction(bool,double) const { return 0L; } // Function Template template int MyFunctionTemplate(X *, Y &) { return Z; } // Const Function Template template int AnotherFunctionTemplate(X &, Z **) const { return Y; } // Static Data static short DSMember; // Static Function static int SIntFunction(long,double) { return 2; } // Static Function Template template static long SFunctionTemplate(long &,A **,B,float) { return 20L; } }; ``` -------------------------------- ### Example Usage of Has Function Metafunctions - C++ Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_detail_has_function Demonstrates the generation and invocation of 'has_function' metafunctions for different inner function names and signatures. It defines sample classes and then uses the metafunctions to check for the existence of specific member functions, illustrating compile-time metaprogramming capabilities. ```cpp #include #include // Generate metafunctions BOOST_TTI_HAS_FUNCTION(function1) BOOST_TTI_HAS_FUNCTION(function2) BOOST_TTI_HAS_FUNCTION(function3) // User-defined types for introspection struct AClass { }; struct Top { static int function1(); AClass function2(double,short *); }; struct Top2 { long function2(Top &,int,bool,short,float); static Top * function3(long,int,AClass &); }; // Invoke metafunctions and check results // has_function_function1::value; // true // has_function_function1::value; // false // has_function_function2 >::value; // true // has_function_function2 >::value; // false // has_function_function3::value; // false // has_function_function3 >::value; // true ``` -------------------------------- ### Define a User-Defined Type with a Member Function Template Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_detail_has_member_function_template This C++ code snippet defines a simple structure `AType` containing a member function template `AFuncTemplate`. This serves as an example for demonstrating TTI introspection. ```cpp struct AType { template double AFuncTemplate(X x,Y * y,Z & z) { ...some code using x,y,z; return 0.0; } }; ``` -------------------------------- ### BOOST_TTI_TRAIT_HAS_TEMPLATE Example with Type Parameters Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/has__template_8hpp_1a73e5a57a50d1822c375124ddb779e960 Example demonstrating how to search for an inner class template called 'MyTemplate' with all template type parameters nested within class 'MyClass'. Shows both variadic and non-variadic macro forms, where MyMeta::value returns a compile-time boolean. ```C++ // Search for an inner class template called 'MyTemplate', with all template type parameters, // nested within the class 'MyClass' using a metafunction name of 'MyMeta'. BOOST_TTI_TRAIT_HAS_TEMPLATE(MyMeta,MyTemplate) // or BOOST_TTI_TRAIT_HAS_TEMPLATE(MyMeta,MyTemplate,BOOST_PP_NIL) // Non-variadic macro form // Usage: MyMeta::value // compile time boolean constant (true or false) ``` -------------------------------- ### Generate metafunction for static member function template using Boost.TTI Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_detail_has_function_template Generates a metafunction using `BOOST_TTI_HAS_FUNCTION_TEMPLATE` to introspect a static member function template. This example demonstrates generating the metafunction for a different instantiation of `AFuncTemplate` within `AType`, including its template parameters and return type. ```cpp #define BOOST_TTI_HAS_FUNCTION_TEMPLATE(name, ...) BOOST_TTI_HAS_FUNCTION_TEMPLATE(AFuncTemplate,long,7435) ``` ```cpp #define BOOST_TTI_HAS_FUNCTION_TEMPLATE_VARIADIC(name, params) BOOST_TTI_HAS_FUNCTION_TEMPLATE(AFuncTemplate,(2,(long,7435))) ``` -------------------------------- ### Check for Template with Specific Parameters using Boost.TTI Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_usingMM This example shows how to check for a nested class template 'MoreParameters' with exactly specified template parameters, including types and templates, using BOOST_TTI_HAS_TEMPLATE. The 'has_template_MoreParameters' helper is utilized. ```cpp BOOST_TTI_HAS_TEMPLATE(MoreParameters,(8,(class,class,int,short,class,template class,class))) has_template_MoreParameters < T > ``` -------------------------------- ### Check for Member Function 'IntFunction' with Individual Types using Boost.TTI Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_usingMM This example shows how to check for a member function 'IntFunction' with a return type of 'int' and a parameter of 'short', using BOOST_TTI_HAS_MEMBER_FUNCTION and boost::mpl::vector. The 'has_member_function_IntFunction' helper is utilized. ```cpp BOOST_TTI_HAS_MEMBER_FUNCTION(IntFunction) has_member_function_IntFunction < T, int, boost::mpl::vector > ``` -------------------------------- ### Check for Member Function (Composite Syntax) Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_func_sig This code snippet demonstrates checking for a member function using the composite syntax of BOOST_TTI_HAS_MEMBER_FUNCTION. It requires including the relevant Boost header and defining the macro. The signature is provided as a single type. A limitation is that if the nested type (U::Ntype in this example) does not exist, it will result in a compiler error. ```cpp #include BOOST_TTI_HAS_MEMBER_FUNCTION(aMemberFunction) has_member_function_aMemberFunction::value; ``` -------------------------------- ### Check for Member Function Template 'MyFunctionTemplate' with Individual Types using Boost.TTI Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_usingMM This example shows how to check for a member function template 'MyFunctionTemplate' with specific template arguments and parameter types using BOOST_TTI_HAS_MEMBER_FUNCTION_TEMPLATE. The 'has_member_function_MyFunctionTemplate' helper is employed. ```cpp BOOST_TTI_HAS_MEMBER_FUNCTION_TEMPLATE(MyFunctionTemplate,short,float,579) has_member_function_MyFunctionTemplate < T, int, boost::mpl::vector > ``` -------------------------------- ### Define and Check Inner Types with BOOST_TTI_HAS_TYPE Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_detail_has_type Demonstrates generating metafunctions for various inner type names and then checking their existence in user-defined types. This example includes the necessary header and defines sample structs with typedefs and nested types. ```cpp #include BOOST_TTI_HAS_TYPE(MyTypeDef) BOOST_TTI_HAS_TYPE(AType) BOOST_TTI_HAS_TYPE(ATypeDef) BOOST_TTI_HAS_TYPE(MyType) struct Top { typedef int MyTypeDef; struct AType { }; }; struct Top2 { typedef long ATypeDef; struct MyType { }; }; has_type_MyTypeDef::value; // true has_type_MyTypeDef::value; // false has_type_AType::value; // true has_type_AType::value; // false has_type_ATypeDef::value; // false has_type_ATypeDef::value; // true has_type_MyType::value; // false has_type_MyType::value; // true ``` -------------------------------- ### BOOST_TTI_HAS_MEMBER_FUNCTION Macro Synopsis Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/has__member__function_8hpp_1a2692b7f6b44f423c2f2603c84a064185 The synopsis for the BOOST_TTI_HAS_MEMBER_FUNCTION macro, indicating the header file where it is defined and its basic usage. ```c++ // In header: BOOST_TTI_HAS_MEMBER_FUNCTION(name) ``` -------------------------------- ### Example: Check for 'MyType' enum existence (C++) Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/has__enum_8hpp_1a61672346ab3da4d5cb47074eb9530621 This example demonstrates how to use the BOOST_TTI_TRAIT_HAS_ENUM macro to create a metafunction named 'LookFor'. This metafunction will check if an inner enum named 'MyType' exists within 'EnclosingType'. The 'value' member of 'LookFor::type' will be true if 'MyType' exists. ```cpp BOOST_TTI_TRAIT_HAS_ENUM(LookFor, MyType) // Usage: // LookFor::value will be true if MyType is an inner enum of EnclosingType. // LookFor::value will be true if MyType exists // and ALambdaExpression invoked with MyType returns true. ``` -------------------------------- ### BOOST_TTI_HAS_MEMBER_DATA Macro Synopsis Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/has__member__data_8hpp_1ac588b80a9a7ae4fc0c65b20f978187f1 The synopsis for the BOOST_TTI_HAS_MEMBER_DATA macro, indicating the header file where it's defined and its basic usage. It takes a single argument, 'name', which is the name of the member to check for. ```cpp // In header: BOOST_TTI_HAS_MEMBER_DATA(name) ``` -------------------------------- ### Example: Check enum type using boost::is_same (C++) Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/has__enum_8hpp_1a61672346ab3da4d5cb47074eb9530621 This example shows a common use case for the optional MPL lambda parameter. It creates a metafunction 'LookFor' that checks if 'MyType' exists in 'EnclosingType' and if it is the same type as 'SomeOtherType' using 'boost::is_same'. This is particularly useful when the enum is a typedef. ```cpp LookFor >::value // This is true if MyType is an inner enum of EnclosingType and is the same type as SomeOtherType. ``` -------------------------------- ### Variadic Macro for Specific Parameters Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_detail_has_template This illustrates the variadic macro usage for introspecting class templates with the 'specific parameters' form. The syntax is simplified, allowing template parameters to be listed directly as subsequent arguments to the macro. This eliminates the need for Boost PP array syntax or BOOST_PP_NIL. ```C++ #define BOOST_TTI_TEMPLATE(ClassName, ...) BOOST_TTI_TEMPLATE(BClassTemplate,class,template class, int) BOOST_TTI_TEMPLATE(CClassTemplate,void (*)(int,long)) BOOST_TTI_TEMPLATE(DClassTemplate,template class) ``` -------------------------------- ### BOOST_TTI_TRAIT_HAS_MEMBER_FUNCTION Macro Synopsis Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/has__member__function_8hpp_1a5a777bc7132dc7c9bb648ba02c5597b9 The synopsis for the BOOST_TTI_TRAIT_HAS_MEMBER_FUNCTION macro, indicating its header file and basic usage. ```cpp // In header: BOOST_TTI_TRAIT_HAS_MEMBER_FUNCTION(trait, name) ``` -------------------------------- ### Metafunction Structure and Return Values Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/has__static__member__function_8hpp_1ab058d4f6390f4294309b9a1b522e1f49 Defines the structure of the metafunction generated by BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION. It outlines the template parameters for type, return type, function signature, and optional tags, as well as the 'value' member which indicates whether the static member function was found. ```cpp template struct has_static_member_function_'name' { static const value = unspecified; typedef mpl::bool_ type; }; // Parameters: // BOOST_TTI_TP_T = Enclosing type (class, struct, or union). // BOOST_TTI_TP_R = Return type or signature of the static member function. // BOOST_TTI_TP_FS = Optional boost::mpl forward sequence for parameters. // BOOST_TTI_TP_TAG = Optional boost::function_types tag. // // Returns: // 'value' is true if the 'name' exists with the correct static member function type, false otherwise. ``` -------------------------------- ### BOOST_TTI_HAS_MEMBER_DATA Metafunction Structure Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/has__member__data_8hpp_1ac588b80a9a7ae4fc0c65b20f978187f1 This code snippet illustrates the structure of the metafunction generated by BOOST_TTI_HAS_MEMBER_DATA. It shows the expected parameters (BOOST_TTI_TP_ET and BOOST_TTI_TP_TYPE) and the return types ('value' and 'type') which indicate the presence and type of the member data. ```cpp template struct has_member_data_'name' { static const value = unspecified; typedef mpl::bool_ type; }; // BOOST_TTI_TP_ET = the enclosing type or a pointer to member data. // BOOST_TTI_TP_TYPE = (optional) the type of the member data. // returns 'value' is true if the 'name' exists with the correct data type, otherwise false. ``` -------------------------------- ### Check for Nested Class Template 'AMemberTemplate' with Boost.TTI Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_usingMM This example shows how to check for a nested class template 'AMemberTemplate' where all template parameters are types, using BOOST_TTI_HAS_TEMPLATE with BOOST_PP_NIL. The 'has_template_AMemberTemplate' helper is used. ```cpp BOOST_TTI_HAS_TEMPLATE(AMemberTemplate,BOOST_PP_NIL) has_template_AMemberTemplate < T > ``` -------------------------------- ### C++ Boost TTI: Valid Member Type Metafunction Description Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/structboost_1_1tti_1_1valid__member__type This C++ code snippet provides a detailed description of the boost::tti::valid_member_type metafunction. It explains the template parameters, the return value ('value' and 'type'), and the criteria for a valid type within the Boost TTI framework. ```cpp template struct valid_member_type { static const value = unspecified; typedef mpl::bool_ type; }; // BOOST_TTI_TP_T = returned inner 'type' from invoking the macro metafunction generated by BOOST_TTI_MEMBER_TYPE ( BOOST_TTI_TRAIT_MEMBER_TYPE ). // BOOST_TTI_TP_MARKER_TYPE = (optional) a type to use as the marker type. // defaults to the internal boost::tti::detail::notype. // returns = 'value' is true if the type is valid, otherwise 'value' is false. // A valid type means that the returned inner 'type' is not the marker type. ``` -------------------------------- ### Check for Member Data 'IntBT' with Specific Type using Boost.TTI Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_usingMM This example shows how to check if a type T has a member data named 'IntBT' of type 'AType::BType' using BOOST_TTI_HAS_MEMBER_DATA. The 'has_member_data_IntBT' helper is employed. ```cpp BOOST_TTI_HAS_MEMBER_DATA(IntBT) has_member_data_IntBT < T, AType::BType > ``` -------------------------------- ### BOOST_TTI_NAMESPACE Macro for Boost TTI Namespace Generation (C++) Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/namespace__gen_8hpp_1a69e0bde53ebf3358969d61a9f4f96514 The BOOST_TTI_NAMESPACE macro generates the name of the Boost TTI namespace. It is declared in the header. The macro's return value is the generated namespace name. ```cpp #include // Example usage (conceptual): // The macro itself doesn't take arguments, it's used to define or reference the namespace. // For instance, it might be used internally by other Boost TTI facilities. // auto tti_namespace_name = BOOST_TTI_NAMESPACE; ``` -------------------------------- ### Check for Static Member Data 'DSMember' with Specific Type using Boost.TTI Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_usingMM This example shows how to check if a type T has a static member data named 'DSMember' of type 'short' using BOOST_TTI_HAS_STATIC_MEMBER_DATA. The 'has_static_member_data_DSMember' helper is employed. ```cpp BOOST_TTI_HAS_STATIC_MEMBER_DATA(DSMember) has_static_member_data_DSMember < T, short > ``` -------------------------------- ### BOOST_TTI_TRAIT_HAS_MEMBER_FUNCTION_TEMPLATE Macro Syntax Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/has__member__function__template_8hpp_1a4af9f9eede857d9c0b56771ea3d57517 The macro syntax for generating a metafunction that tests for the existence of a member function template. It accepts a trait name, function name, and variadic parameters representing either direct instantiation types or a Boost PP array. ```cpp BOOST_TTI_TRAIT_HAS_MEMBER_FUNCTION_TEMPLATE(trait, name, ...) ``` -------------------------------- ### Detecting Templates with Boost.TTI Macros Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/has__template_8hpp This snippet demonstrates the basic syntax for using Boost.TTI macros to detect the presence of templates. These macros are part of the Type Trait Introspection library, enabling compile-time introspection of C++ types. They do not require external dependencies beyond the Boost library itself. ```cpp BOOST_TTI_TRAIT_HAS_TEMPLATE(trait, ...) BOOST_TTI_HAS_TEMPLATE(...) ``` -------------------------------- ### Check for Const Member Function Template 'AnotherFunctionTemplate' with Individual Types using Boost.TTI Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_usingMM This example shows how to check for a const member function template 'AnotherFunctionTemplate' with specific template arguments and parameter types using BOOST_TTI_HAS_MEMBER_FUNCTION_TEMPLATE. The 'has_member_function_AnotherFunctionTemplate' helper is employed. ```cpp BOOST_TTI_HAS_MEMBER_FUNCTION_TEMPLATE(AnotherFunctionTemplate,bool,8359,double) has_member_function_AnotherFunctionTemplate < T, int, boost::mpl::vector, boost::function_types::const_qualified > ``` -------------------------------- ### Define User-Defined Types for Data Introspection Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_detail_has_data Defines example classes with various member data (instance and static) that will be introspected. The Top and Top2 structs contain different data types including primitive types, pointers, and custom class members. ```C++ struct AClass { }; struct Top { int data1; static AClass * data2; }; struct Top2 { static long data1; Top data3; }; ``` -------------------------------- ### Invoke metafunction to check for static member function template using Boost.TTI Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_detail_has_function_template Invokes the metafunction to check for the existence of a static member function template. This example shows how to use the generated metafunction with the enclosing type, return type, and function parameters for the static member function template. ```cpp has_function_template_AFuncTemplate >::value ``` -------------------------------- ### BOOST_TTI_TRAIT_HAS_STATIC_MEMBER_DATA Macro Syntax Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/has__static__member__data_8hpp_1a58f89caab6ba2738f7bbef1c311f296a Defines the macro syntax for creating a metafunction to detect static member data. The macro takes two parameters: the trait name and the member name. It expands into a template metafunction that can be instantiated with an enclosing type and a member data type to perform compile-time introspection. ```cpp BOOST_TTI_TRAIT_HAS_STATIC_MEMBER_DATA(trait, name) ``` -------------------------------- ### Check for Const Member Function 'AnotherFunction' with Individual Types using Boost.TTI Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_usingMM This example shows how to check for a const member function 'AnotherFunction' returning 'long' and taking 'bool, double' using BOOST_TTI_HAS_MEMBER_FUNCTION, boost::mpl::vector, and boost::function_types::const_qualified. The 'has_member_function_AnotherFunction' helper is employed. ```cpp BOOST_TTI_HAS_MEMBER_FUNCTION(AnotherFunction) has_member_function_AnotherFunction < T, long, boost::mpl::vector, boost::function_types::const_qualified > ``` -------------------------------- ### BOOST_TTI_TRAIT_HAS_STATIC_MEMBER_DATA Generated Metafunction Structure Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/has__static__member__data_8hpp_1a58f89caab6ba2738f7bbef1c311f296a Shows the structure of the generated metafunction template created by the macro. The metafunction takes two template parameters: the enclosing type and the type of the static member data. It provides a static boolean value and a type member indicating whether the static member exists with the specified name and type. ```cpp template struct trait { static const value = unspecified; typedef mpl::bool_ type; }; ``` -------------------------------- ### Boost TTI - Check for Nested Type 'AClass' in C++ Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_usingMM This C++ code snippet demonstrates how to use the BOOST_TTI_HAS_TYPE macro to check if a given type 'T' has a nested type named 'AClass'. The metafunction 'has_type_ACLass' (note the typo in the original example) will return a compile-time boolean value. ```cpp BOOST_TTI_HAS_TYPE(AClass) has_type_ACLass < T > ``` -------------------------------- ### Boost.TTI Type Generation Macro Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/has__type__gen_8hpp Defines a macro for generating type-checking facilities within the Boost.TTI library. This macro simplifies the process of creating custom type traits. ```cpp #define BOOST_TTI_HAS_TYPE_GEN(name) ``` -------------------------------- ### Define user types for member data introspection Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_detail_has_member_data Shows example user-defined types (struct definitions) that will be introspected to check for specific member data. These types demonstrate various member data configurations including primitive types, pointers, and nested types that can be checked using the generated metafunctions. ```cpp struct AClass { }; struct Top { int data1; AClass * data2; }; struct Top2 { long data1; Top data3; }; ``` -------------------------------- ### Metafunction Structure for has_function_template Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/has__function__template_8hpp_1ab2d264e7ad580ada8d14bc87b16d78d9 This shows the structure of the metafunction generated by BOOST_TTI_HAS_FUNCTION_TEMPLATE. It provides a 'value' member indicating existence and a 'type' member as an mpl_bool. The template parameters specify the type to inspect, the return type, function parameters, and an optional tag. ```C++ template struct has_function_template_'name' { static const value = unspecified; typedef mpl::bool_ type; }; // Explanation of template parameters: // BOOST_TTI_TP_T: The enclosing type to search within. // BOOST_TTI_R: The return type of the function template. // BOOST_TTI_FS: (Optional) A Boost PP sequence of function template parameters. // BOOST_TTI_TAG: (Optional) A Boost function type tag. ``` -------------------------------- ### Generate BOOST_TTI_HAS_DATA Metafunction Name Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/has__data__gen_8hpp_1a4d46859a1e2f7383332f200710b428d4 The BOOST_TTI_HAS_DATA_GEN macro is used to generate the name for a metafunction that checks for the existence of data members. It takes the data name as input and returns the generated metafunction name. This macro is defined in the header. ```c++ #include // Example usage: // BOOST_TTI_HAS_DATA_GEN(my_data) ``` -------------------------------- ### BOOST_TTI_HAS_MEMBER_FUNCTION Metafunction Structure Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/has__member__function_8hpp_1a2692b7f6b44f423c2f2603c84a064185 The generated metafunction structure for BOOST_TTI_HAS_MEMBER_FUNCTION, outlining its template parameters and return types for checking member function existence. ```c++ template struct has_member_function_''name'' { static const value = unspecified; typedef mpl::bool_ type; }; The metafunction types and return: BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'. The enclosing type can be a class, struct, or union. OR a pointer to member function as a single type. BOOST_TTI_TP_R = (optional) the return type of the member function if the first parameter is the enclosing type. BOOST_TTI_TP_FS = (optional) the parameters of the member function as a boost::mpl forward sequence if the first parameter is the enclosing type and the member function parameters are not empty. BOOST_TTI_TP_TAG = (optional) a boost::function_types tag to apply to the member function if the first parameter is the enclosing type and a tag is needed. returns = 'value' is true if the 'name' exists, with the appropriate member function type, otherwise 'value' is false. ``` -------------------------------- ### Generate Metafunction Name for BOOST_TTI_HAS_FUNCTION (C++) Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/has__function__gen_8hpp_1ad00416093182fe0101f97d0edeb958fa The BOOST_TTI_HAS_FUNCTION_GEN macro is used to generate the name of a metafunction for the BOOST_TTI_HAS_FUNCTION macro. It takes the desired function name as input and outputs the corresponding metafunction name. This is part of the Boost.TTI library, requiring the header. ```c++ #include // Example usage: // BOOST_TTI_HAS_FUNCTION_GEN(myFunction) will generate a name like has_myFunction_member ``` -------------------------------- ### Introspect Member Function Existence and Signature Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_detail_has_member_function This example shows how to invoke the generated metafunctions to introspect member functions. It covers two ways of invoking the metafunction: by providing the enclosing type and the member function's return type and parameter types separately, or by providing a pointer to the member function. The result, a compile-time boolean constant 'value', indicates whether the member function exists with the specified signature. ```cpp struct AClass { }; struct Top { int function1(); AClass function2(double,short *); }; struct Top2 { long function2(Top &,int,bool,short,float); Top * function3(long,int,AClass &); }; // Invoking metafunctions has_member_function_function1::value; // true has_member_function_function1 >::value; // true has_member_function_function1::value; // false has_member_function_function2::value; // true has_member_function_function2::value; // false has_member_function_function2::value; // true has_member_function_function3::value; // false has_member_function_function3 >::value; // true; ``` -------------------------------- ### Generate Metafunction for Static Member Function Template (Non-Variadic) Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_detail_has_static_member_function_template Generates a metafunction to check for the existence of a static member function template named 'AStaticFuncTemplate' with specific instantiated template parameters 'char' and '483'. This is an alternative form for compilers without variadic macro support, using a Boost PP array. ```C++ #define BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION_TEMPLATE(AStaticFuncTemplate,(2,(char,483))) ``` -------------------------------- ### Check for Static Member Function (Composite Syntax) Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_func_sig This code demonstrates checking for a static member function using the composite syntax of BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION. It includes the necessary Boost header and defines the macro. The signature is provided in a composite format. A drawback is that if the specified nested type (U::Ntype) does not exist, a compiler error will occur. ```cpp #include BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION(aStaticMemberFunction) has_static_member_function_aStaticMemberFunction::value; ``` -------------------------------- ### Non-Variadic Macro for Specific Parameters Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_detail_has_template This demonstrates the non-variadic macro usage for introspecting class templates using the 'specific parameters' form. It involves providing the class template name and a Boost preprocessor library array data type representing the template parameters. Careful attention is needed to correctly count array parameters, especially with template template parameters or non-type template parameters involving parentheses. ```C++ #define BOOST_TTI_TEMPLATE(ClassName, Params) BOOST_TTI_TEMPLATE(AClassTemplate,(4,(class,typename,class,typename))) BOOST_TTI_TEMPLATE(BClassTemplate,(3,(class, template class, int))) ``` ```C++ template class CClassTemplate { /* etc. */ }; template class T> class DClassTemplate { /* etc. */ }; BOOST_TTI_TEMPLATE(CClassTemplate,(1,(void (*)(int,long)))) BOOST_TTI_TEMPLATE(DClassTemplate,(2,(template class))) ``` -------------------------------- ### Detect Static Member Function Templates with Boost.TTI Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/has__static__member__function__template_8hpp These macros from the Boost.TTI library allow compile-time detection of static member function templates within a given type. They are useful for metaprogramming tasks where you need to conditionally compile code based on the availability of specific member functions. No external dependencies are required beyond the Boost.TTI header. ```cpp BOOST_TTI_TRAIT_HAS_STATIC_MEMBER_FUNCTION_TEMPLATE(trait, name, ...) BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION_TEMPLATE(name, ...) ``` -------------------------------- ### Check for Data Member Existence with Boost TTI (C++) Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/has__data_8hpp These macros from allow introspection of C++ types to determine if they possess a data member with a specific name. BOOST_TTI_TRAIT_HAS_DATA defines a trait, while BOOST_TTI_HAS_DATA provides a simpler interface. They require no external dependencies beyond the Boost C++ Libraries. ```c++ #include BOOST_TTI_TRAIT_HAS_DATA(trait_name, data_member_name) BOOST_TTI_HAS_DATA(data_member_name) ``` -------------------------------- ### Define a Static Member Function Template Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_detail_has_static_member_function_template This code defines a simple struct 'AnotherType' with a static member function template 'AStaticFuncTemplate'. This template takes two template parameters (a type X and an integer Y) and a function parameter of type X, returning an int. ```C++ struct AnotherType { template static int AStaticFuncTemplate(X x) { ...some code using x; return Y; } }; ``` -------------------------------- ### Generate Metafunction for Static Member Function Template (Variadic) Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_detail_has_static_member_function_template Generates a metafunction to check for the existence of a static member function template named 'AStaticFuncTemplate' with specific instantiated template parameters 'char' and '483'. This is the variadic macro form. ```C++ #define BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION_TEMPLATE(AStaticFuncTemplate,char,483) ``` -------------------------------- ### BOOST_TTI_TRAIT_HAS_MEMBER_FUNCTION_TEMPLATE Generated Metafunction Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/has__member__function__template_8hpp_1a4af9f9eede857d9c0b56771ea3d57517 The metafunction structure generated by the macro. It contains static value and type members that indicate whether the specified member function template exists. The template parameters define the enclosing type, return type, parameter sequence, and optional function type tag. ```cpp template struct trait { static const value = unspecified; typedef mpl::bool_ type; }; ``` -------------------------------- ### Invoke Metafunction with Separate Parameters Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_detail_has_member_function_template This C++ code demonstrates how to invoke the generated metafunction to check for the existence of a member function template. It passes the enclosing type, return type, and function parameters as separate arguments, with parameters enclosed in an MPL forward sequence. ```cpp has_member_function_template_AFuncTemplate >::value ``` -------------------------------- ### Check for Nested Type Existence Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/the_type_traits_introspection_library/tti_nested_type Demonstrates checking for the existence of a deeply nested type 'FindType' using TTI macros. It also shows how to use 'boost::tti::valid_member_type' for a more concise existence check. ```cpp BOOST_TTI_MEMBER_TYPE(FindType) BOOST_TTI_MEMBER_TYPE(AType) BOOST_TTI_MEMBER_TYPE(BType) BOOST_TTI_MEMBER_TYPE(CType) BOOST_TTI_HAS_TYPE(FindType) has_type_FindType < typename member_type_CType < typename member_type_BType < typename member_type_AType < T >::type >::type >::type > boost::tti::valid_member_type < MyFindType > ``` -------------------------------- ### Boost TTI Macros for Member Type Detection Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/member__type_8hpp These macros are part of the Boost.TTI (Type Traits) library and are used to define traits for detecting the presence and type of member types within a given C++ type. They simplify the process of creating custom type traits for compile-time checks. ```cpp BOOST_TTI_TRAIT_MEMBER_TYPE(trait, name) BOOST_TTI_MEMBER_TYPE(name) ``` -------------------------------- ### BOOST_TTI_TRAIT_HAS_MEMBER_DATA Macro Definition and Usage Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/has__member__data_8hpp_1a0274738af7fe2894ad1e1283a16ea323 Defines and demonstrates the BOOST_TTI_TRAIT_HAS_MEMBER_DATA macro syntax. The macro generates a metafunction that checks for member data existence by name and type. It accepts a trait name parameter and member data name, producing a template struct with a static boolean value and mpl::bool_ type indicating whether the member data exists. ```cpp // In header: BOOST_TTI_TRAIT_HAS_MEMBER_DATA(trait, name) template struct trait { static const value = unspecified; typedef mpl::bool_ type; }; ``` -------------------------------- ### BOOST_TTI_TRAIT_HAS_DATA Macro Definition Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/has__data_8hpp_1a167acce13c15b366a14597ee93816bb8 Macro expansion syntax for BOOST_TTI_TRAIT_HAS_DATA. This macro is used to generate a metafunction that tests for the existence of member data or static member data with a specified name and type. The macro takes two parameters: the name of the resulting metafunction and the name of the member data to search for. ```C++ BOOST_TTI_TRAIT_HAS_DATA(trait, name) ``` -------------------------------- ### Generated Metafunction Structure (C++) Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/has__static__member__function__template_8hpp_1a742af91950cfd5ddb7b1ae0471ef1918 When BOOST_TTI_TRAIT_HAS_STATIC_MEMBER_FUNCTION_TEMPLATE is used, it generates a metafunction with a specific structure. This metafunction includes a 'value' member indicating existence and a 'type' member representing the result as an mpl_bool. ```cpp template struct trait_name { static const value = unspecified; // true or false typedef mpl::bool_ type; }; // Where: // BOOST_TTI_TP_T: The enclosing type to inspect. // BOOST_TTI_R: The return type of the static member function template. // BOOST_TTI_FS: Optional sequence of parameters for the static member function template. // BOOST_TTI_TAG: Optional Boost.FunctionTypes tag. ``` -------------------------------- ### Metafunction Structure for has_static_member_function_template Source: https://www.boost.org/doc/libs/latest/libs/tti/doc/html/doxygen/reference/has__static__member__function__template_8hpp_1a1a0cadb61d0d636473e54167872e6532 This structure represents the metafunction generated by BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION_TEMPLATE. It provides a 'value' member that is true if the specified static member function template exists with the correct types, and false otherwise. The template parameters define the type to inspect, the return type, function parameters, and an optional function type tag. ```cpp template struct has_static_member_function_template_name { static const value = unspecified; typedef mpl::bool_ type; }; ```