• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 //  (C) Copyright Edward Diener 2019
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_CLASS_HPP)
8 #define BOOST_TTI_HAS_CLASS_HPP
9 
10 #include <boost/config.hpp>
11 #include <boost/preprocessor/cat.hpp>
12 #include <boost/tti/gen/has_class_gen.hpp>
13 #include <boost/tti/gen/namespace_gen.hpp>
14 #include <boost/tti/detail/dclass.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 /// A macro which expands to a metafunction which tests whether an inner class/struct with a particular name exists.
27 /**
28 
29     BOOST_TTI_TRAIT_HAS_CLASS is a macro which expands to a metafunction.
30     The metafunction tests whether an inner class/struct with a particular name exists
31     and, optionally, whether an MPL lambda expression invoked with the inner class/struct
32     is true or not. The macro takes the form of BOOST_TTI_TRAIT_HAS_CLASS(trait,name) where
33 
34     trait = the name of the metafunction <br/>
35     name  = the name of the inner class/struct.
36 
37     BOOST_TTI_TRAIT_HAS_CLASS generates a metafunction called "trait" where 'trait' is the macro parameter.
38 
39   @code
40 
41               template<class BOOST_TTI_TP_T,class BOOST_TTI_TP_U>
42               struct trait
43                 {
44                 static const value = unspecified;
45                 typedef mpl::bool_<true-or-false> type;
46                 };
47 
48               The metafunction types and return:
49 
50                 BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'.
51                                  The enclosing type can be a class, struct, or union.
52 
53                 BOOST_TTI_TP_U = (optional) An optional template parameter, defaulting to a marker type.
54                                    If specified it is an MPL lambda expression which is invoked
55                                    with the inner class/struct found and must return a constant boolean
56                                    value.
57 
58                 returns = 'value' depends on whether or not the optional BOOST_TTI_TP_U is specified.
59 
60                           If BOOST_TTI_TP_U is not specified, then 'value' is true if the 'name' class/struct
61                           exists within the enclosing type BOOST_TTI_TP_T; otherwise 'value' is false.
62 
63                           If BOOST_TTI_TP_U is specified , then 'value' is true if the 'name' class/struct exists
64                           within the enclosing type BOOST_TTI_TP_T and the MPL lambda expression as specified
65                           by BOOST_TTI_TP_U, invoked by passing the actual inner class/struct of 'name', returns
66                           a 'value' of true; otherwise 'value' is false.
67 
68                           The action taken with BOOST_TTI_TP_U occurs only when the 'name' class/struct exists
69                           within the enclosing type BOOST_TTI_TP_T.
70 
71   @endcode
72 
73   Example usage:
74 
75   @code
76 
77   BOOST_TTI_TRAIT_HAS_CLASS(LookFor,MyType) generates the metafunction "LookFor" in the current scope
78   to look for an inner class/struct called MyType.
79 
80   LookFor<EnclosingType>::value is true if MyType is an inner class/struct of EnclosingType, otherwise false.
81 
82   LookFor<EnclosingType,ALambdaExpression>::value is true if MyType is an inner class/struct of EnclosingType
83     and invoking ALambdaExpression with the inner class/struct returns a value of true, otherwise false.
84 
85   A popular use of the optional MPL lambda expression is to check whether the class/struct found is the same
86   as another type, when the class/struct found is a typedef. In that case our example would be:
87 
88   LookFor<EnclosingType,boost::is_same<_,SomeOtherType> >::value is true if MyType is an inner class/struct
89     of EnclosingType and is the same type as SomeOtherType.
90 
91   @endcode
92 
93 */
94 #define BOOST_TTI_TRAIT_HAS_CLASS(trait,name) \
95   BOOST_TTI_DETAIL_TRAIT_HAS_CLASS(trait,name) \
96   template \
97     < \
98     class BOOST_TTI_TP_T, \
99     class BOOST_TTI_TP_U = BOOST_TTI_NAMESPACE::detail::deftype \
100     > \
101   struct trait \
102     { \
103     typedef typename \
104     BOOST_PP_CAT(trait,_detail_class)<BOOST_TTI_TP_T,BOOST_TTI_TP_U>::type type; \
105     BOOST_STATIC_CONSTANT(bool,value=type::value); \
106     }; \
107 /**/
108 
109 /// A macro which expands to a metafunction which tests whether an inner class/struct with a particular name exists.
110 /**
111 
112     BOOST_TTI_HAS_CLASS is a macro which expands to a metafunction.
113     The metafunction tests whether an inner class/struct with a particular name exists
114     and, optionally, whether an MPL lambda expression invoked with the inner class/struct
115     is true or not. The macro takes the form of BOOST_TTI_HAS_CLASS(name) where
116 
117     name  = the name of the inner class/struct.
118 
119     BOOST_TTI_HAS_CLASS generates a metafunction called "has_class_'name'" where 'name' is the macro parameter.
120 
121   @code
122 
123               template<class BOOST_TTI_TP_T,class BOOST_TTI_TP_U>
124               struct has_class_'name'
125                 {
126                 static const value = unspecified;
127                 typedef mpl::bool_<true-or-false> type;
128                 };
129 
130               The metafunction types and return:
131 
132                 BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'.
133                                  The enclosing type can be a class, struct, or union.
134 
135                 BOOST_TTI_TP_U = (optional) An optional template parameter, defaulting to a marker type.
136                                    If specified it is an MPL lambda expression which is invoked
137                                    with the inner class/struct found and must return a constant boolean
138                                    value.
139 
140                 returns = 'value' depends on whether or not the optional BOOST_TTI_TP_U is specified.
141 
142                           If BOOST_TTI_TP_U is not specified, then 'value' is true if the 'name' class/struct
143                           exists within the enclosing type BOOST_TTI_TP_T; otherwise 'value' is false.
144 
145                           If BOOST_TTI_TP_U is specified, then 'value' is true if the 'name' class/struct exists
146                           within the enclosing type BOOST_TTI_TP_T and the MPL lambda expression as specified
147                           by BOOST_TTI_TP_U, invoked by passing the actual inner class/struct of 'name', returns
148                           a 'value' of true; otherwise 'value' is false.
149 
150                           The action taken with BOOST_TTI_TP_U occurs only when the 'name' class/struct exists
151                           within the enclosing type BOOST_TTI_TP_T.
152 
153   @endcode
154 
155   Example usage:
156 
157   @code
158 
159   BOOST_TTI_HAS_CLASS(MyType) generates the metafunction "has_class_MyType" in the current scope
160   to look for an inner class/struct called MyType.
161 
162   has_class_MyType<EnclosingType>::value is true if MyType is an inner class/struct of EnclosingType, otherwise false.
163 
164   has_class_MyType<EnclosingType,ALambdaExpression>::value is true if MyType is an inner class/struct of EnclosingType
165     and invoking ALambdaExpression with the inner class/struct returns a value of true, otherwise false.
166 
167   A popular use of the optional MPL lambda expression is to check whether the class/struct found is the same
168   as another type, when the class/struct found is a typedef. In that case our example would be:
169 
170   has_class_MyType<EnclosingType,boost::is_same<_,SomeOtherType> >::value is true if MyType is an inner class/struct
171     of EnclosingType and is the same type as SomeOtherType.
172 
173   @endcode
174 
175 */
176 #define BOOST_TTI_HAS_CLASS(name) \
177   BOOST_TTI_TRAIT_HAS_CLASS \
178   ( \
179   BOOST_TTI_HAS_CLASS_GEN(name), \
180   name \
181   ) \
182 /**/
183 
184 #endif // BOOST_TTI_HAS_CLASS_HPP
185