PageRenderTime 31ms CodeModel.GetById 7ms RepoModel.GetById 1ms app.codeStats 0ms

/boost_1_57_0/boost/tti/has_template.hpp

http://github.com/MisterTea/HyperNEAT
C++ Header | 348 lines | 53 code | 14 blank | 281 comment | 0 complexity | 0fa295c9512c2f798c4bc479ef543834 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0, GPL-3.0, GPL-2.0
  1. // (C) Copyright Edward Diener 2011,2012
  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. /*
  6. The succeeding comments in this file are in doxygen format.
  7. */
  8. /** \file
  9. */
  10. #if !defined(BOOST_TTI_HAS_TEMPLATE_HPP)
  11. #define BOOST_TTI_HAS_TEMPLATE_HPP
  12. #include <boost/config.hpp>
  13. #include <boost/tti/gen/has_template_gen.hpp>
  14. #include <boost/preprocessor/config/config.hpp>
  15. #include <boost/preprocessor/control/iif.hpp>
  16. #if BOOST_PP_VARIADICS
  17. #include <boost/preprocessor/comparison/equal.hpp>
  18. #include <boost/preprocessor/variadic/elem.hpp>
  19. #include <boost/preprocessor/variadic/size.hpp>
  20. #include <boost/tti/detail/dvm_template_params.hpp>
  21. /// Expands to a metafunction which tests whether an inner class template with a particular name exists.
  22. /**
  23. trait = the name of the metafunction.
  24. ... = variadic parameters.
  25. The first variadic parameter is the inner class template name.
  26. Following variadic parameters are optional.
  27. If no following variadic parameters exist, then the inner class template
  28. being introspected must be all template type parameters ( template parameters
  29. starting with `class` or `typename` ) and any number of template type parameters
  30. can occur.
  31. If the second variadic parameter is BOOST_PP_NIL and no other variadic
  32. parameter is given, then just as in the previous case the inner class template
  33. being introspected must be all template type parameters ( template parameters
  34. starting with `class` or `typename` ) and any number of template type parameters
  35. can occur. This form is allowed in order to be consistent with using the
  36. non-variadic form of this macro.
  37. If the second variadic parameter is a Boost preprocessor library array and no other
  38. variadic parameter is given, then the inner class template must have its template
  39. parameters matching the sequence in the tuple portion of the Boost PP array. This
  40. form is allowed in order to be consistent with using the non-variadic form of this
  41. macro.
  42. Otherwise the inner class template must have its template parameters matching the
  43. sequence of the optional variadic parameters.
  44. generates a metafunction called "trait" where 'trait' is the first macro parameter.
  45. template<class BOOST_TTI_TP_T>
  46. struct trait
  47. {
  48. static const value = unspecified;
  49. typedef mpl::bool_<true-or-false> type;
  50. };
  51. The metafunction types and return:
  52. BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'.
  53. returns = 'value' is true if the 'name' template exists within the enclosing type,
  54. otherwise 'value' is false.
  55. Examples:
  56. 1) Search for an inner class template called 'MyTemplate', with all template type parameters,
  57. nested within the class 'MyClass' using a metafunction name of 'MyMeta'.
  58. BOOST_TTI_TRAIT_HAS_TEMPLATE(MyMeta,MyTemplate)
  59. or
  60. BOOST_TTI_TRAIT_HAS_TEMPLATE(MyMeta,MyTemplate,BOOST_PP_NIL) // Non-variadic macro form
  61. MyMeta<MyClass>::value
  62. is a compile time boolean constant which is either 'true' or 'false'
  63. if the nested template exists.
  64. 2) Search for an inner class template called 'MyTemplate', with template parameters
  65. of 'class T,int x,template<class> class U', nested within the class 'MyClass'
  66. using a metafunction name of 'MyMeta'.
  67. BOOST_TTI_TRAIT_HAS_TEMPLATE(MyMeta,MyTemplate,class,int,template<class> class)
  68. or
  69. BOOST_TTI_TRAIT_HAS_TEMPLATE(MyMeta,MyTemplate,(3,(class,int,template<class> class))) // Non-variadic macro form
  70. MyMeta<MyClass>::value
  71. is a compile time boolean constant which is either 'true' or 'false'
  72. if the nested template exists.
  73. */
  74. #define BOOST_TTI_TRAIT_HAS_TEMPLATE(trait,...) \
  75. BOOST_PP_IIF \
  76. ( \
  77. BOOST_PP_EQUAL \
  78. ( \
  79. BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), \
  80. 1 \
  81. ), \
  82. BOOST_TTI_DETAIL_VM_TRAIT_HAS_TEMPLATE, \
  83. BOOST_TTI_DETAIL_VM_CHECK_MORE_THAN_TWO \
  84. ) \
  85. (trait,__VA_ARGS__) \
  86. /**/
  87. /// Expands to a metafunction which tests whether an inner class template with a particular name exists.
  88. /**
  89. ... = variadic parameters.
  90. The first variadic parameter is the inner class template name.
  91. Following variadic parameters are optional.
  92. If no following variadic parameters exist, then the inner class template
  93. being introspected must be all template type parameters ( template parameters
  94. starting with `class` or `typename` ) and any number of template type parameters
  95. can occur.
  96. If the second variadic parameter is BOOST_PP_NIL and no other variadic
  97. parameter is given, then just as in the previous case the inner class template
  98. being introspected must be all template type parameters ( template parameters
  99. starting with `class` or `typename` ) and any number of template type parameters
  100. can occur. This form is allowed in order to be consistent with using the
  101. non-variadic form of this macro.
  102. If the second variadic parameter is a Boost preprocessor library array and no other
  103. variadic parameter is given, then the inner class template must have its template
  104. parameters matching the sequence in the tuple portion of the Boost PP array. This
  105. form is allowed in order to be consistent with using the non-variadic form of this
  106. macro.
  107. Otherwise the inner class template must have its template parameters matching the
  108. sequence of the optional variadic parameters.
  109. generates a metafunction called "has_template_'name'" where 'name' is the first variadic parameter.
  110. template<class BOOST_TTI_TP_T>
  111. struct has_template_'name'
  112. {
  113. static const value = unspecified;
  114. typedef mpl::bool_<true-or-false> type;
  115. };
  116. The metafunction types and return:
  117. BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'.
  118. returns = 'value' is true if the 'name' template exists within the enclosing type,
  119. otherwise 'value' is false.
  120. Examples:
  121. 1) Search for an inner class template called 'MyTemplate', with all template type parameters,
  122. nested within the class 'MyClass'.
  123. BOOST_TTI_HAS_TEMPLATE(MyTemplate)
  124. or
  125. BOOST_TTI_HAS_TEMPLATE(MyTemplate,BOOST_PP_NIL) // Non-variadic macro form
  126. has_template_MyTemplate<MyClass>::value
  127. is a compile time boolean constant which is either 'true' or 'false'
  128. if the nested template exists.
  129. 2) Search for an inner class template called 'MyTemplate' with template parameters
  130. of 'class T,int x,template<class> class U' nested within the class 'MyClass'.
  131. BOOST_TTI_HAS_TEMPLATE(MyTemplate,class,int,template<class> class)
  132. or
  133. BOOST_TTI_HAS_TEMPLATE(MyTemplate,(3,(class,int,template<class> class))) // Non-variadic macro form
  134. has_template_MyTemplate<MyClass>::value
  135. is a compile time boolean constant which is either 'true' or 'false'
  136. if the nested template exists.
  137. */
  138. #define BOOST_TTI_HAS_TEMPLATE(...) \
  139. BOOST_TTI_TRAIT_HAS_TEMPLATE \
  140. ( \
  141. BOOST_TTI_HAS_TEMPLATE_GEN \
  142. ( \
  143. BOOST_PP_VARIADIC_ELEM(0,__VA_ARGS__) \
  144. ), \
  145. __VA_ARGS__ \
  146. ) \
  147. /**/
  148. #else // !BOOST_PP_VARIADICS
  149. #include <boost/preprocessor/detail/is_binary.hpp>
  150. #include <boost/tti/detail/dtemplate.hpp>
  151. #include <boost/tti/detail/dtemplate_params.hpp>
  152. /// Expands to a metafunction which tests whether an inner class template with a particular name exists.
  153. /**
  154. trait = the name of the metafunction.
  155. name = the inner class template name.
  156. params = If the parameter is BOOST_PP_NIL the inner class template
  157. being introspected must be all template type parameters ( template parameters
  158. starting with `class` or `typename` ) and any number of template type parameters
  159. can occur.
  160. If the parameter is a Boost preprocessor library array, then the inner class
  161. template must have its template parameters matching the sequence in the tuple portion
  162. of the Boost PP array.
  163. Otherwise a compiler error occurs.
  164. generates a metafunction called "trait" where 'trait' is the first macro parameter.
  165. template<class BOOST_TTI_TP_T>
  166. struct trait
  167. {
  168. static const value = unspecified;
  169. typedef mpl::bool_<true-or-false> type;
  170. };
  171. The metafunction types and return:
  172. BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'.
  173. returns = 'value' is true if the 'name' template exists within the enclosing type,
  174. otherwise 'value' is false.
  175. Examples:
  176. 1) Search for an inner class template called 'MyTemplate', with all template type parameters,
  177. nested within the class 'MyClass' using a metafunction name of 'MyMeta'.
  178. BOOST_TTI_TRAIT_HAS_TEMPLATE(MyMeta,MyTemplate,BOOST_PP_NIL)
  179. MyMeta<MyClass>::value
  180. is a compile time boolean constant which is either 'true' or 'false'
  181. if the nested template exists.
  182. 2) Search for an inner class template called 'MyTemplate', with template parameters
  183. of 'class T,int x,template<class> class U', nested within the class 'MyClass'
  184. using a metafunction name of 'MyMeta'.
  185. BOOST_TTI_TRAIT_HAS_TEMPLATE(MyMeta,MyTemplate,(3,(class,int,template<class> class)))
  186. MyMeta<MyClass>::value
  187. is a compile time boolean constant which is either 'true' or 'false'
  188. if the nested template exists.
  189. */
  190. #define BOOST_TTI_TRAIT_HAS_TEMPLATE(trait,name,params) \
  191. BOOST_PP_IIF \
  192. ( \
  193. BOOST_PP_IS_BINARY(params), \
  194. BOOST_TTI_DETAIL_TRAIT_HAS_TEMPLATE_CHECK_PARAMS, \
  195. BOOST_TTI_DETAIL_TRAIT_CHECK_IS_NIL \
  196. ) \
  197. (trait,name,params) \
  198. /**/
  199. /// Expands to a metafunction which tests whether an inner class template with a particular name exists.
  200. /**
  201. name = the inner class template name.
  202. params = If the parameter is BOOST_PP_NIL the inner class template
  203. being introspected must be all template type parameters ( template parameters
  204. starting with `class` or `typename` ) and any number of template type parameters
  205. can occur.
  206. If the parameter is a Boost preprocessor library array, then the inner class
  207. template must have its template parameters matching the sequence in the tuple portion
  208. of the Boost PP array.
  209. Otherwise a compiler error occurs.
  210. generates a metafunction called "has_template_'name'" where 'name' is the first macro parameter.
  211. template<class BOOST_TTI_TP_T>
  212. struct trait
  213. {
  214. static const value = unspecified;
  215. typedef mpl::bool_<true-or-false> type;
  216. };
  217. The metafunction types and return:
  218. BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'.
  219. returns = 'value' is true if the 'name' template exists within the enclosing type,
  220. otherwise 'value' is false.
  221. Examples:
  222. 1) Search for an inner class template called 'MyTemplate', with all template type parameters,
  223. nested within the class 'MyClass'.
  224. BOOST_TTI_HAS_TEMPLATE(MyTemplate,BOOST_PP_NIL)
  225. has_template_MyTemplate<MyClass>::value
  226. is a compile time boolean constant which is either 'true' or 'false'
  227. if the nested template exists.
  228. 2) Search for an inner class template called 'MyTemplate' with template parameters
  229. of 'class T,int x,template<class> class U' nested within the class 'MyClass'.
  230. BOOST_TTI_HAS_TEMPLATE(MyTemplate,(3,(class,int,template<class> class)))
  231. has_template_MyTemplate<MyClass>::value
  232. is a compile time boolean constant which is either 'true' or 'false'
  233. if the nested template exists.
  234. */
  235. #define BOOST_TTI_HAS_TEMPLATE(name,params) \
  236. BOOST_TTI_TRAIT_HAS_TEMPLATE \
  237. ( \
  238. BOOST_TTI_HAS_TEMPLATE_GEN(name), \
  239. name, \
  240. params \
  241. ) \
  242. /**/
  243. #endif // BOOST_PP_VARIADICS
  244. #endif // BOOST_TTI_HAS_TEMPLATE_HPP