has_function_template.hpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. // (C) Copyright Edward Diener 2019
  2. // Use, modification and distribution are subject to the Boost Software License,
  3. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt).
  5. #if !defined(BOOST_TTI_FUNCTION_TEMPLATE_HPP)
  6. #define BOOST_TTI_FUNCTION_TEMPLATE_HPP
  7. #include <boost/config.hpp>
  8. #include <boost/function_types/property_tags.hpp>
  9. #include <boost/mpl/vector.hpp>
  10. #include <boost/preprocessor/cat.hpp>
  11. #include <boost/tti/gen/namespace_gen.hpp>
  12. #include <boost/tti/gen/has_function_template_gen.hpp>
  13. #include <boost/tti/detail/dfunction_template.hpp>
  14. #if BOOST_PP_VARIADICS
  15. #include <boost/tti/detail/dmacro_fun_template.hpp>
  16. /*
  17. The succeeding comments in this file are in doxygen format.
  18. */
  19. /** \file
  20. */
  21. /// A macro which expands to a metafunction which tests whether an inner member function template or static member function template with a particular name exists.
  22. /**
  23. BOOST_TTI_TRAIT_HAS_FUNCTION_TEMPLATE is a macro which expands to a metafunction.
  24. The metafunction tests whether an inner member function template or static member function template with a particular name exists.
  25. The macro takes the form of BOOST_TTI_TRAIT_HAS_FUNCTION_TEMPLATE(trait,name,...) where
  26. trait = the name of the metafunction <br/>
  27. name = inner member function template or static member function template name <br/>
  28. ... = variadic parameters.
  29. The variadic parameter(s) are either:
  30. A sequence of valid instantiations for the static member function template parameters
  31. ie. 'int,long,double' etc.
  32. or
  33. A single variadic parameter which is a Boost PP array whose elements are
  34. a sequence of valid instantiations for the static member function template parameters
  35. ie. '(3,(int,long,double))' etc. This form is allowed in order to be compatible
  36. with using the non-variadic form of this macro.
  37. BOOST_TTI_TRAIT_HAS_FUNCTION_TEMPLATE generates a metafunction called "trait" where 'trait' is the first macro parameter.
  38. @code
  39. template<class BOOST_TTI_TP_T,class BOOST_TTI_R,class BOOST_TTI_FS,class BOOST_TTI_TAG>
  40. struct trait
  41. {
  42. static const value = unspecified;
  43. typedef mpl::bool_<true-or-false> type;
  44. };
  45. The metafunction types and return:
  46. BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'.
  47. The enclosing type can be a class, struct, or union.
  48. BOOST_TTI_TP_R = the return type of the function template
  49. in a single instantiation of the function template
  50. BOOST_TTI_TP_FS = (optional) the parameters of the function template as a boost::mpl forward sequence
  51. if the function template parameters are not empty. These parameters are a single
  52. instantiation of the function template.
  53. BOOST_TTI_TP_TAG = (optional) a boost::function_types tag to apply to the function template
  54. if a tag is needed.
  55. returns = 'value' is true if the 'name' exists,
  56. with the appropriate member function template or static member function template type,
  57. otherwise 'value' is false.
  58. @endcode
  59. */
  60. #define BOOST_TTI_TRAIT_HAS_FUNCTION_TEMPLATE(trait,name,...) \
  61. BOOST_TTI_DETAIL_TRAIT_HAS_FUNCTION_TEMPLATE \
  62. ( \
  63. trait, \
  64. name, \
  65. BOOST_TTI_DETAIL_FUN_TEMPLATE_VARIADIC_TO_ARRAY(__VA_ARGS__) \
  66. ) \
  67. template<class BOOST_TTI_TP_T,class BOOST_TTI_TP_R,class BOOST_TTI_TP_FS = boost::mpl::vector<>,class BOOST_TTI_TP_TAG = boost::function_types::null_tag> \
  68. struct trait \
  69. { \
  70. typedef typename \
  71. BOOST_PP_CAT(trait,_detail_hft)<BOOST_TTI_TP_T,BOOST_TTI_TP_R,BOOST_TTI_TP_FS,BOOST_TTI_TP_TAG>::type type; \
  72. BOOST_STATIC_CONSTANT(bool,value=type::value); \
  73. }; \
  74. /**/
  75. /// A macro which expands to a metafunction which tests whether an inner member function template or static member function template with a particular name exists.
  76. /**
  77. BOOST_TTI__HAS_FUNCTION_TEMPLATE is a macro which expands to a metafunction.
  78. The metafunction tests whether an inner member function template or static member function template with a particular name exists.
  79. The macro takes the form of BOOST_TTI_HAS_FUNCTION_TEMPLATE(name,...) where
  80. name = inner member function template or static member function template name <br/>
  81. ... = variadic parameters.
  82. The variadic parameter(s) are either:
  83. A sequence of valid instantiations for the static member function template parameters
  84. ie. 'int,long,double' etc.
  85. or
  86. A single variadic parameter which is a Boost PP array whose elements are
  87. a sequence of valid instantiations for the static member function template parameters
  88. ie. '(3,(int,long,double))' etc. This form is allowed in order to be compatible
  89. with using the non-variadic form of this macro.
  90. BOOST_TTI_HAS_FUNCTION_TEMPLATE generates a metafunction called "has_function_template_'name'" where 'name' is the first macro parameter.
  91. @code
  92. template<class BOOST_TTI_TP_T,class BOOST_TTI_R,class BOOST_TTI_FS,class BOOST_TTI_TAG>
  93. struct has_function_template_'name'
  94. {
  95. static const value = unspecified;
  96. typedef mpl::bool_<true-or-false> type;
  97. };
  98. The metafunction types and return:
  99. BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'.
  100. The enclosing type can be a class, struct, or union.
  101. BOOST_TTI_TP_R = the return type of the function template
  102. in a single instantiation of the function template
  103. BOOST_TTI_TP_FS = (optional) the parameters of the function template as a boost::mpl forward sequence
  104. if the function template parameters are not empty. These parameters are a single
  105. instantiation of the function template.
  106. BOOST_TTI_TP_TAG = (optional) a boost::function_types tag to apply to the function template
  107. if a tag is needed.
  108. returns = 'value' is true if the 'name' exists,
  109. with the appropriate member function template or static member function template type,
  110. otherwise 'value' is false.
  111. @endcode
  112. */
  113. #define BOOST_TTI_HAS_FUNCTION_TEMPLATE(name,...) \
  114. BOOST_TTI_TRAIT_HAS_FUNCTION_TEMPLATE \
  115. ( \
  116. BOOST_TTI_HAS_FUNCTION_TEMPLATE_GEN(name), \
  117. name, \
  118. __VA_ARGS__ \
  119. ) \
  120. /**/
  121. #else // !BOOST_PP_VARIADICS
  122. /*
  123. The succeeding comments in this file are in doxygen format.
  124. */
  125. /** \file
  126. */
  127. /// A macro which expands to a metafunction which tests whether an inner member function template or static member function template with a particular name exists.
  128. /**
  129. BOOST_TTI_TRAIT_HAS_FUNCTION_TEMPLATE is a macro which expands to a metafunction.
  130. The metafunction tests whether an inner member function template or static member function template with a particular name exists.
  131. The macro takes the form of BOOST_TTI_TRAIT_HAS_FUNCTION_TEMPLATE(trait,name,pparray) where
  132. trait = the name of the metafunction <br/>
  133. name = inner member function template or static member function template name <br/>
  134. pparray = a Boost PP array whose elements are a sequence of valid instantiations for
  135. the static member function template parameters ie. '(3,(int,long,double))' etc.
  136. BOOST_TTI_TRAIT_HAS_FUNCTION_TEMPLATE generates a metafunction called "trait" where 'trait' is the first macro parameter.
  137. @code
  138. template<class BOOST_TTI_TP_T,class BOOST_TTI_R,class BOOST_TTI_FS,class BOOST_TTI_TAG>
  139. struct trait
  140. {
  141. static const value = unspecified;
  142. typedef mpl::bool_<true-or-false> type;
  143. };
  144. The metafunction types and return:
  145. BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'.
  146. The enclosing type can be a class, struct, or union.
  147. BOOST_TTI_TP_R = the return type of the function template
  148. in a single instantiation of the function template
  149. BOOST_TTI_TP_FS = (optional) the parameters of the function template as a boost::mpl forward sequence
  150. if the function template parameters are not empty. These parameters are a single
  151. instantiation of the function template.
  152. BOOST_TTI_TP_TAG = (optional) a boost::function_types tag to apply to the function template
  153. if a tag is needed.
  154. returns = 'value' is true if the 'name' exists,
  155. with the appropriate member function template or static member function template type,
  156. otherwise 'value' is false.
  157. @endcode
  158. */
  159. #define BOOST_TTI_TRAIT_HAS_FUNCTION_TEMPLATE(trait,name,pparray) \
  160. BOOST_TTI_DETAIL_TRAIT_HAS_FUNCTION_TEMPLATE(trait,name,pparray) \
  161. template<class BOOST_TTI_TP_T,class BOOST_TTI_TP_R,class BOOST_TTI_TP_FS = boost::mpl::vector<>,class BOOST_TTI_TP_TAG = boost::function_types::null_tag> \
  162. struct trait \
  163. { \
  164. typedef typename \
  165. BOOST_PP_CAT(trait,_detail_hft)<BOOST_TTI_TP_T,BOOST_TTI_TP_R,BOOST_TTI_TP_FS,BOOST_TTI_TP_TAG>::type type; \
  166. BOOST_STATIC_CONSTANT(bool,value=type::value); \
  167. }; \
  168. /**/
  169. /// A macro which expands to a metafunction which tests whether an inner member function template or static member function template with a particular name exists.
  170. /**
  171. BOOST_TTI_HAS_FUNCTION_TEMPLATE is a macro which expands to a metafunction.
  172. The metafunction tests whether an inner member function template or static member function template with a particular name exists.
  173. The macro takes the form of BOOST_TTI_HAS_FUNCTION_TEMPLATE(name,pparray) where
  174. name = inner member function template or static member function template name <br/>
  175. pparray = a Boost PP array whose elements are a sequence of valid instantiations for
  176. the static member function template parameters ie. '(3,(int,long,double))' etc.
  177. BOOST_TTI_HAS_FUNCTION_TEMPLATE generates a metafunction called "has_function_template_'name'" where 'name' is the first macro parameter.
  178. @code
  179. template<class BOOST_TTI_TP_T,class BOOST_TTI_R,class BOOST_TTI_FS,class BOOST_TTI_TAG>
  180. struct has_function_template_'name'
  181. {
  182. static const value = unspecified;
  183. typedef mpl::bool_<true-or-false> type;
  184. };
  185. The metafunction types and return:
  186. BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'.
  187. The enclosing type can be a class, struct, or union.
  188. BOOST_TTI_TP_R = the return type of the function template
  189. in a single instantiation of the function template
  190. BOOST_TTI_TP_FS = (optional) the parameters of the function template as a boost::mpl forward sequence
  191. if the function template parameters are not empty. These parameters are a single
  192. instantiation of the function template.
  193. BOOST_TTI_TP_TAG = (optional) a boost::function_types tag to apply to the function template
  194. if a tag is needed.
  195. returns = 'value' is true if the 'name' exists,
  196. with the appropriate member function template or static member function template type,
  197. otherwise 'value' is false.
  198. @endcode
  199. */
  200. #define BOOST_TTI_HAS_FUNCTION_TEMPLATE(name,pparray) \
  201. BOOST_TTI_TRAIT_HAS_FUNCTION_TEMPLATE \
  202. ( \
  203. BOOST_TTI_HAS_FUNCTION_TEMPLATE_GEN(name), \
  204. name, \
  205. pparray \
  206. ) \
  207. /**/
  208. #endif // BOOST_PP_VARIADICS
  209. #endif // BOOST_TTI_FUNCTION_TEMPLATE_HPP