]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
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_ENUM_HPP) | |
8 | #define BOOST_TTI_HAS_ENUM_HPP | |
9 | ||
10 | #include <boost/config.hpp> | |
11 | #include <boost/preprocessor/cat.hpp> | |
12 | #include <boost/tti/gen/has_enum_gen.hpp> | |
13 | #include <boost/tti/gen/namespace_gen.hpp> | |
14 | #include <boost/tti/detail/denum.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 enum with a particular name exists. | |
27 | /** | |
28 | ||
29 | BOOST_TTI_TRAIT_HAS_ENUM is a macro which expands to a metafunction. | |
30 | The metafunction tests whether an inner enum with a particular name exists | |
31 | and, optionally, whether an MPL lambda expression invoked with the inner enum | |
32 | is true or not. The macro takes the form of BOOST_TTI_TRAIT_HAS_ENUM(trait,name) where | |
33 | ||
34 | trait = the name of the metafunction <br/> | |
35 | name = the name of the inner enum. The name can be that of an enum or, in C++11 on up, an enum class. | |
36 | ||
37 | BOOST_TTI_TRAIT_HAS_ENUM 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 enum 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' enum | |
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' enum 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 enum 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' enum 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_ENUM(LookFor,MyType) generates the metafunction LookFor in the current scope | |
78 | to look for an inner enum called MyType. | |
79 | ||
80 | LookFor<EnclosingType>::value is true if MyType is an inner enum of EnclosingType, otherwise false. | |
81 | ||
82 | LookFor<EnclosingType,ALambdaExpression>::value is true if MyType is an inner enum of EnclosingType | |
83 | and invoking ALambdaExpression with the inner enum returns a value of true, otherwise false. | |
84 | ||
85 | A popular use of the optional MPL lambda expression is to check whether the enum found is the same | |
86 | as another type, when the enum 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 enum | |
89 | of EnclosingType and is the same type as SomeOtherType. | |
90 | ||
91 | @endcode | |
92 | ||
93 | */ | |
94 | #define BOOST_TTI_TRAIT_HAS_ENUM(trait,name) \ | |
95 | BOOST_TTI_DETAIL_TRAIT_HAS_ENUM(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_enum)<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 enum with a particular name exists. | |
110 | /** | |
111 | ||
112 | BOOST_TTI_HAS_ENUM is a macro which expands to a metafunction. | |
113 | The metafunction tests whether an inner enum with a particular name exists | |
114 | and, optionally, whether an MPL lambda expression invoked with the inner enum | |
115 | is true or not. The macro takes the form of BOOST_TTI_HAS_ENUM(name) where | |
116 | ||
117 | name = the name of the inner enum. The name can be that of an enum or, in C++11 on up, an enum class. | |
118 | ||
119 | BOOST_TTI_HAS_ENUM generates a metafunction called "has_enum_'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_enum_'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 enum 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' enum | |
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' enum 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 enum 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' enum 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_ENUM(MyType) generates the metafunction has_enum_MyType in the current scope | |
160 | to look for an inner enum called MyType. | |
161 | ||
162 | has_enum_MyType<EnclosingType>::value is true if MyType is an inner enum of EnclosingType, otherwise false. | |
163 | ||
164 | has_class_MyType<EnclosingType,ALambdaExpression>::value is true if MyType is an inner enum of EnclosingType | |
165 | and invoking ALambdaExpression with the inner enum returns a value of true, otherwise false. | |
166 | ||
167 | A popular use of the optional MPL lambda expression is to check whether the enum found is the same | |
168 | as another type, when the enum found is a typedef. In that case our example would be: | |
169 | ||
170 | has_enum_MyType<EnclosingType,boost::is_same<_,SomeOtherType> >::value is true if MyType is an inner enum | |
171 | of EnclosingType and is the same type as SomeOtherType. | |
172 | ||
173 | @endcode | |
174 | ||
175 | */ | |
176 | #define BOOST_TTI_HAS_ENUM(name) \ | |
177 | BOOST_TTI_TRAIT_HAS_ENUM \ | |
178 | ( \ | |
179 | BOOST_TTI_HAS_ENUM_GEN(name), \ | |
180 | name \ | |
181 | ) \ | |
182 | /**/ | |
183 | ||
184 | #endif // BOOST_TTI_HAS_ENUM_HPP |