has_class.hpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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_HAS_CLASS_HPP)
  6. #define BOOST_TTI_HAS_CLASS_HPP
  7. #include <boost/config.hpp>
  8. #include <boost/preprocessor/cat.hpp>
  9. #include <boost/tti/gen/has_class_gen.hpp>
  10. #include <boost/tti/gen/namespace_gen.hpp>
  11. #include <boost/tti/detail/dclass.hpp>
  12. #include <boost/tti/detail/ddeftype.hpp>
  13. /*
  14. The succeeding comments in this file are in doxygen format.
  15. */
  16. /** \file
  17. */
  18. /// A macro which expands to a metafunction which tests whether an inner class/struct with a particular name exists.
  19. /**
  20. BOOST_TTI_TRAIT_HAS_CLASS is a macro which expands to a metafunction.
  21. The metafunction tests whether an inner class/struct with a particular name exists
  22. and, optionally, whether an MPL lambda expression invoked with the inner class/struct
  23. is true or not. The macro takes the form of BOOST_TTI_TRAIT_HAS_CLASS(trait,name) where
  24. trait = the name of the metafunction <br/>
  25. name = the name of the inner class/struct.
  26. BOOST_TTI_TRAIT_HAS_CLASS generates a metafunction called "trait" where 'trait' is the macro parameter.
  27. @code
  28. template<class BOOST_TTI_TP_T,class BOOST_TTI_TP_U>
  29. struct trait
  30. {
  31. static const value = unspecified;
  32. typedef mpl::bool_<true-or-false> type;
  33. };
  34. The metafunction types and return:
  35. BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'.
  36. The enclosing type can be a class, struct, or union.
  37. BOOST_TTI_TP_U = (optional) An optional template parameter, defaulting to a marker type.
  38. If specified it is an MPL lambda expression which is invoked
  39. with the inner class/struct found and must return a constant boolean
  40. value.
  41. returns = 'value' depends on whether or not the optional BOOST_TTI_TP_U is specified.
  42. If BOOST_TTI_TP_U is not specified, then 'value' is true if the 'name' class/struct
  43. exists within the enclosing type BOOST_TTI_TP_T; otherwise 'value' is false.
  44. If BOOST_TTI_TP_U is specified , then 'value' is true if the 'name' class/struct exists
  45. within the enclosing type BOOST_TTI_TP_T and the MPL lambda expression as specified
  46. by BOOST_TTI_TP_U, invoked by passing the actual inner class/struct of 'name', returns
  47. a 'value' of true; otherwise 'value' is false.
  48. The action taken with BOOST_TTI_TP_U occurs only when the 'name' class/struct exists
  49. within the enclosing type BOOST_TTI_TP_T.
  50. @endcode
  51. Example usage:
  52. @code
  53. BOOST_TTI_TRAIT_HAS_CLASS(LookFor,MyType) generates the metafunction "LookFor" in the current scope
  54. to look for an inner class/struct called MyType.
  55. LookFor<EnclosingType>::value is true if MyType is an inner class/struct of EnclosingType, otherwise false.
  56. LookFor<EnclosingType,ALambdaExpression>::value is true if MyType is an inner class/struct of EnclosingType
  57. and invoking ALambdaExpression with the inner class/struct returns a value of true, otherwise false.
  58. A popular use of the optional MPL lambda expression is to check whether the class/struct found is the same
  59. as another type, when the class/struct found is a typedef. In that case our example would be:
  60. LookFor<EnclosingType,boost::is_same<_,SomeOtherType> >::value is true if MyType is an inner class/struct
  61. of EnclosingType and is the same type as SomeOtherType.
  62. @endcode
  63. */
  64. #define BOOST_TTI_TRAIT_HAS_CLASS(trait,name) \
  65. BOOST_TTI_DETAIL_TRAIT_HAS_CLASS(trait,name) \
  66. template \
  67. < \
  68. class BOOST_TTI_TP_T, \
  69. class BOOST_TTI_TP_U = BOOST_TTI_NAMESPACE::detail::deftype \
  70. > \
  71. struct trait \
  72. { \
  73. typedef typename \
  74. BOOST_PP_CAT(trait,_detail_class)<BOOST_TTI_TP_T,BOOST_TTI_TP_U>::type type; \
  75. BOOST_STATIC_CONSTANT(bool,value=type::value); \
  76. }; \
  77. /**/
  78. /// A macro which expands to a metafunction which tests whether an inner class/struct with a particular name exists.
  79. /**
  80. BOOST_TTI_HAS_CLASS is a macro which expands to a metafunction.
  81. The metafunction tests whether an inner class/struct with a particular name exists
  82. and, optionally, whether an MPL lambda expression invoked with the inner class/struct
  83. is true or not. The macro takes the form of BOOST_TTI_HAS_CLASS(name) where
  84. name = the name of the inner class/struct.
  85. BOOST_TTI_HAS_CLASS generates a metafunction called "has_class_'name'" where 'name' is the macro parameter.
  86. @code
  87. template<class BOOST_TTI_TP_T,class BOOST_TTI_TP_U>
  88. struct has_class_'name'
  89. {
  90. static const value = unspecified;
  91. typedef mpl::bool_<true-or-false> type;
  92. };
  93. The metafunction types and return:
  94. BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'.
  95. The enclosing type can be a class, struct, or union.
  96. BOOST_TTI_TP_U = (optional) An optional template parameter, defaulting to a marker type.
  97. If specified it is an MPL lambda expression which is invoked
  98. with the inner class/struct found and must return a constant boolean
  99. value.
  100. returns = 'value' depends on whether or not the optional BOOST_TTI_TP_U is specified.
  101. If BOOST_TTI_TP_U is not specified, then 'value' is true if the 'name' class/struct
  102. exists within the enclosing type BOOST_TTI_TP_T; otherwise 'value' is false.
  103. If BOOST_TTI_TP_U is specified, then 'value' is true if the 'name' class/struct exists
  104. within the enclosing type BOOST_TTI_TP_T and the MPL lambda expression as specified
  105. by BOOST_TTI_TP_U, invoked by passing the actual inner class/struct of 'name', returns
  106. a 'value' of true; otherwise 'value' is false.
  107. The action taken with BOOST_TTI_TP_U occurs only when the 'name' class/struct exists
  108. within the enclosing type BOOST_TTI_TP_T.
  109. @endcode
  110. Example usage:
  111. @code
  112. BOOST_TTI_HAS_CLASS(MyType) generates the metafunction "has_class_MyType" in the current scope
  113. to look for an inner class/struct called MyType.
  114. has_class_MyType<EnclosingType>::value is true if MyType is an inner class/struct of EnclosingType, otherwise false.
  115. has_class_MyType<EnclosingType,ALambdaExpression>::value is true if MyType is an inner class/struct of EnclosingType
  116. and invoking ALambdaExpression with the inner class/struct returns a value of true, otherwise false.
  117. A popular use of the optional MPL lambda expression is to check whether the class/struct found is the same
  118. as another type, when the class/struct found is a typedef. In that case our example would be:
  119. has_class_MyType<EnclosingType,boost::is_same<_,SomeOtherType> >::value is true if MyType is an inner class/struct
  120. of EnclosingType and is the same type as SomeOtherType.
  121. @endcode
  122. */
  123. #define BOOST_TTI_HAS_CLASS(name) \
  124. BOOST_TTI_TRAIT_HAS_CLASS \
  125. ( \
  126. BOOST_TTI_HAS_CLASS_GEN(name), \
  127. name \
  128. ) \
  129. /**/
  130. #endif // BOOST_TTI_HAS_CLASS_HPP