1 2 // (C) Copyright Edward Diener 2011,2012,2013 3 // Use, modification and distribution are subject to the Boost Software License, 4 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 // http://www.boost.org/LICENSE_1_0.txt). 6 7 #if !defined(BOOST_TTI_HAS_TYPE_HPP) 8 #define BOOST_TTI_HAS_TYPE_HPP 9 10 #include <boost/config.hpp> 11 #include <boost/preprocessor/cat.hpp> 12 #include <boost/tti/gen/has_type_gen.hpp> 13 #include <boost/tti/gen/namespace_gen.hpp> 14 #include <boost/tti/detail/dtype.hpp> 15 #include <boost/tti/detail/ddeftype.hpp> 16 17 /* 18 19 The succeeding comments in this file are in doxygen format. 20 21 */ 22 23 /** \file 24 */ 25 26 /** 27 28 BOOST_TTI_TRAIT_HAS_TYPE is a macro which expands to a metafunction. 29 The metafunction tests whether an inner type with a particular name exists 30 and, optionally, whether a lambda expression invoked with the inner type 31 is true or not. 32 33 trait = the name of the metafunction within the tti namespace. 34 35 name = the name of the inner type. 36 37 generates a metafunction called "trait" where 'trait' is the macro parameter. 38 39 template<class BOOST_TTI_TP_T,class BOOST_TTI_TP_U> 40 struct trait 41 { 42 static const value = unspecified; 43 typedef mpl::bool_<true-or-false> type; 44 }; 45 46 The metafunction types and return: 47 48 BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'. 49 50 BOOST_TTI_TP_U = (optional) An optional template parameter, defaulting to a marker type. 51 If specified it is an MPL lambda expression which is invoked 52 with the inner type found and must return a constant boolean 53 value. 54 55 returns = 'value' depends on whether or not the optional BOOST_TTI_TP_U is specified. 56 57 If BOOST_TTI_TP_U is not specified, then 'value' is true if the 'name' type 58 exists within the enclosing type BOOST_TTI_TP_T; otherwise 'value' is false. 59 60 If BOOST_TTI_TP_U is specified , then 'value' is true if the 'name' type exists 61 within the enclosing type BOOST_TTI_TP_T and the lambda expression as specified 62 by BOOST_TTI_TP_U, invoked by passing the actual inner type of 'name', returns 63 a 'value' of true; otherwise 'value' is false. 64 65 The action taken with BOOST_TTI_TP_U occurs only when the 'name' type exists 66 within the enclosing type BOOST_TTI_TP_T. 67 68 Example usage: 69 70 BOOST_TTI_TRAIT_HAS_TYPE(LookFor,MyType) generates the metafunction LookFor in the current scope 71 to look for an inner type called MyType. 72 73 LookFor<EnclosingType>::value is true if MyType is an inner type of EnclosingType, otherwise false. 74 75 LookFor<EnclosingType,ALambdaExpression>::value is true if MyType is an inner type of EnclosingType 76 and invoking ALambdaExpression with the inner type returns a value of true, otherwise false. 77 78 A popular use of the optional MPL lambda expression is to check whether the type found is the same 79 as another type, when the type found is a typedef. In that case our example would be: 80 81 LookFor<EnclosingType,boost::is_same<_,SomeOtherType> >::value is true if MyType is an inner type 82 of EnclosingType and is the same type as SomeOtherType. 83 84 */ 85 #define BOOST_TTI_TRAIT_HAS_TYPE(trait,name) \ 86 BOOST_TTI_DETAIL_TRAIT_HAS_TYPE(trait,name) \ 87 template \ 88 < \ 89 class BOOST_TTI_TP_T, \ 90 class BOOST_TTI_TP_U = BOOST_TTI_NAMESPACE::detail::deftype \ 91 > \ 92 struct trait \ 93 { \ 94 typedef typename \ 95 BOOST_PP_CAT(trait,_detail_type)<BOOST_TTI_TP_T,BOOST_TTI_TP_U>::type type; \ 96 BOOST_STATIC_CONSTANT(bool,value=type::value); \ 97 }; \ 98 /**/ 99 100 /** 101 102 BOOST_TTI_HAS_TYPE is a macro which expands to a metafunction. 103 The metafunction tests whether an inner type with a particular name exists 104 and, optionally, whether a lambda expression invoked with the inner type 105 is true or not. 106 107 name = the name of the inner type. 108 109 generates a metafunction called "has_type_'name'" where 'name' is the macro parameter. 110 111 template<class BOOST_TTI_TP_T,class BOOST_TTI_TP_U> 112 struct has_type_'name' 113 { 114 static const value = unspecified; 115 typedef mpl::bool_<true-or-false> type; 116 }; 117 118 The metafunction types and return: 119 120 BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'. 121 122 BOOST_TTI_TP_U = (optional) An optional template parameter, defaulting to a marker type. 123 If specified it is an MPL lambda expression which is invoked 124 with the inner type found and must return a constant boolean 125 value. 126 127 returns = 'value' depends on whether or not the optional BOOST_TTI_TP_U is specified. 128 129 If BOOST_TTI_TP_U is not specified, then 'value' is true if the 'name' type 130 exists within the enclosing type BOOST_TTI_TP_T; otherwise 'value' is false. 131 132 If BOOST_TTI_TP_U is specified , then 'value' is true if the 'name' type exists 133 within the enclosing type BOOST_TTI_TP_T and the lambda expression as specified 134 by BOOST_TTI_TP_U, invoked by passing the actual inner type of 'name', returns 135 a 'value' of true; otherwise 'value' is false. 136 137 The action taken with BOOST_TTI_TP_U occurs only when the 'name' type exists 138 within the enclosing type BOOST_TTI_TP_T. 139 140 Example usage: 141 142 BOOST_TTI_HAS_TYPE(MyType) generates the metafunction has_type_MyType in the current scope 143 to look for an inner type called MyType. 144 145 has_type_MyType<EnclosingType>::value is true if MyType is an inner type of EnclosingType, otherwise false. 146 147 has_type_MyType<EnclosingType,ALambdaExpression>::value is true if MyType is an inner type of EnclosingType 148 and invoking ALambdaExpression with the inner type returns a value of true, otherwise false. 149 150 A popular use of the optional MPL lambda expression is to check whether the type found is the same 151 as another type, when the type found is a typedef. In that case our example would be: 152 153 has_type_MyType<EnclosingType,boost::is_same<_,SomeOtherType> >::value is true if MyType is an inner type 154 of EnclosingType and is the same type as SomeOtherType. 155 156 */ 157 #define BOOST_TTI_HAS_TYPE(name) \ 158 BOOST_TTI_TRAIT_HAS_TYPE \ 159 ( \ 160 BOOST_TTI_HAS_TYPE_GEN(name), \ 161 name \ 162 ) \ 163 /**/ 164 165 #endif // BOOST_TTI_HAS_TYPE_HPP 166