1[/ 2 (C) Copyright Edward Diener 2020 3 Distributed under the Boost Software License, Version 1.0. 4 (See accompanying file LICENSE_1_0.txt or copy at 5 http://www.boost.org/LICENSE_1_0.txt). 6] 7 8[section:tti_detail_has_static_member_function_template Introspecting static member function template] 9 10We can introspect a static member function template of a user-defined type 11using the TTI functionality we shall now explain. 12 13A static member function template is a function template that is a static memmber 14of a user-defined type. An example of a static member function template would be: 15 16 struct AnotherType 17 { 18 template<class X,int Y> static int AStaticFuncTemplate(X x) { ...some code using x; return Y; } 19 }; 20 21In order to introspect the function template we use some theoretical valid instantiation of 22the static member function template `AStaticFuncTemplate`. An instantiation of a function template 23was previously explained in the topic [link sectti_function_templates "Introspecting function templates technique"]. 24 25For the purposes of illustration the instantiation we will use is: 26 27 int AStaticFuncTemplate<char,483>(char) 28 29What we have now which the TTI will need in order to introspect the static member 30function template `template<class X,int Y> static int AStaticFuncTemplate(X)` 31within the `AnotherType` struct is: 32 33* The name of `AStaticFuncTemplate` 34* The template parameters of `char,483` 35* The enclosing type of `AnotherType` 36* The return type of `int` 37* The function parameters of `char` 38 39[heading Generating the metafunction] 40 41As with all TTI functionality for introspecting entities within a user-defined 42type introspecting a static member function template is a two step process. The first 43process is using a macro to generate a metafunction. The macro for 44static member function templates is [macroref BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION_TEMPLATE]. 45This macro takes the name of the member function template and the instantiated 46template parameters, the first two items in our list above: 47 48 BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION_TEMPLATE(AStaticFuncTemplate,char,483) 49 50An alternative form for compilers which do not support variadic macros, and which will 51also work with compilers which do support variadic macros, is to specify 52the template parameters of the instantiation as a single macro argument using a 53Boost PP array: 54 55 BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION_TEMPLATE(AStaticFuncTemplate,(2,(char,483))) 56 57The macro generates a metafunction based on the pattern of 58"has_static_member_function_template_'name_of_inner_static_member_function_template'", 59which in our example case would be `has_static_member_function_template_AStaticFuncTemplate`. 60 61[heading Invoking the metafunction] 62 63To use this macro to test whether our static member function template exists 64the metafunction the macro creates is invoked with the enclosing type, the instantiated return type, 65and the instantiated function parameters, with the resulting `value` being a compile time 66boolean constant which is `true` if the static member function template exists, 67or `false` otherwise. There are two ways to do this. We can either 68use each of our needed types as separate parameters, with the instantiated function parameters 69being enclosed in an MPL forward sequence, or we can compose our needed type 70in the form of an enclosing type and a function type. In the first case we would have: 71 72 has_static_member_function_template_AStaticFuncTemplate<AnotherType,int,boost::mpl::vector<char> >::value 73 74and in the second case we would have: 75 76 has_static_member_function_template_AStaticFuncTemplate<AnotherType,int (char) >::value 77 78Both invocations are equivalent in functionality. 79 80[heading Other considerations] 81 82The macro for generating the metafunction for introspecting member function templates 83also has, like other macros in the TTI library, a complex macro form where the 84end-user can directly specify the name of the metafunction to be generated. The 85corresponding macro is BOOST_TTI_TRAIT_HAS_STATIC_MEMBER_FUNCTION_TEMPLATE, 86where the first parameter is the name of the metafunction to be generated, 87the second parameter is the static member function template name, and the remaining parameters 88are the instantiated template parameters. For our example we could have 89 90 BOOST_TTI_TRAIT_HAS_STATIC_MEMBER_FUNCTION_TEMPLATE(AMetafunctionName,AStaticFuncTemplate,char,483) 91 92or for the non-variadic macro form 93 94 BOOST_TTI_TRAIT_HAS_STATIC_MEMBER_FUNCTION_TEMPLATE(AMetafunctionName,AStaticFuncTemplate,(2,(char,483))) 95 96which generates a metafunction whose name would be `AMetafunctionName`. 97 98In all other respects the resulting metafunction generated works exactly the same 99as when using the simpler macro form previously illustrated. 100 101If you do use the simple macro form, which generates the metafunction name 102from the name of the function template you are introspecting, you can use 103a corresponding macro, taking the name of the static member function template 104as a single parameter, to create the appropriate metafunction name if you do not want to 105remember the pattern for generating the metafunction name. This macro name is 106`BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION_TEMPLATE_GEN` as in 107 108 BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION_TEMPLATE_GEN(AStaticFuncTemplate) 109 110which would generate the name `has_static_member_function_template_AStaticFuncTemplate`. 111 112When invoking the appropriate metafunction using the long form of an enclosing 113type, instantiated return type, and instantiated function parameters, a fourth 114template argument may optionally be given which holds a Boost FunctionTypes tag 115type. This optional template argument is of much less use for static member 116function templates than for non-static member function templates since static 117member function templates, like static member functions, can not have 118cv-qualifications. which a number of Boost FunctionTypes tags provide. 119Nonetheless this optional Boost FunctionTypes tag is available for 120end-user use and may come in handy in certain rare cases, as when some calling 121convention qualification for the static member function template needs to be 122specified. 123 124When invoking the metafunction using the shorter form of an enclosing type and a 125function type any possibly needed qualification can be added to the end of the 126function type. 127 128[endsect] 129