]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/tti/doc/tti_using_mm.qbk
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / tti / doc / tti_using_mm.qbk
1 [/
2 (C) Copyright Edward Diener 2011,2012
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE_1_0.txt or copy at
5 http://www.boost.org/LICENSE_1_0.txt).
6 ]
7
8 [section:tti_usingMM An example using the Macro Metafunctions]
9 [#sectti_usingMM]
10
11 Using the macro metafunctions can be illustrated by first creating some hypothetical
12 user-defined type with corresponding nested types and other inner elements.
13 With this type we can illustrate the use of the macro metafunctions. This is
14 just meant to serve as a model for what a type T might entail from within
15 a class or function template where 'T' is a type passed to the template.
16
17 // An enclosing type
18
19 struct AType
20 {
21
22 // Type
23
24 typedef int AnIntType; // as a typedef
25
26 struct BType // as a nested type
27 {
28 struct CType
29 {
30 };
31 };
32
33 // Template
34
35 template <class> struct AMemberTemplate { };
36 template <class,class,class> struct AnotherMemberTemplate { };
37 template <class,class,int,class,template <class> class,class,long> struct ManyParameters { };
38 template <class,class,int,short,class,template <class,int> class,class> struct MoreParameters { };
39
40 // Data
41
42 BType IntBT;
43
44 // Function
45
46 int IntFunction(short) { return 0; }
47
48 // Static Data
49
50 static short DSMember;
51
52 // Static Function
53
54 static int SIntFunction(long,double) { return 2; }
55
56 };
57
58 I will be using the type above just to illustrate the sort of
59 metaprogramming questions we can ask of some type T which is passed
60 to the template programmer in a class template. Here is what the
61 class template might look like:
62
63 #include <boost/tti/tti.hpp>
64
65 template<class T>
66 struct OurTemplateClass
67 {
68
69 // compile-time template code regarding T
70
71 };
72
73 Now let us create and invoke the macro metafunctions for each of our inner element types,
74 to see if type T above corresponds to our hypothetical type above. Imagine this being
75 within 'OurTemplateClass' above. In the examples below the same macro is invoked just once
76 to avoid ODR violations.
77
78 [heading Type]
79
80 Does T have a nested type called 'AnIntType' ?
81
82 BOOST_TTI_HAS_TYPE(AnIntType)
83
84 has_type_AnIntType
85 <
86 T
87 >
88
89 Does T have a nested type called 'BType' ?
90
91 BOOST_TTI_HAS_TYPE(BType)
92
93 has_type_BType
94 <
95 T
96 >
97
98 [heading Type checking the typedef using a lambda expression]
99
100 Does T have a nested typedef called 'AnIntType' whose type is an 'int' ?
101
102 #include <boost/mpl/placeholders.hpp
103 #include <boost/type_traits/is_same.hpp
104 using namespace boost::mpl::placeholders;
105
106 has_type_AnIntType
107 <
108 T,
109 boost::is_same<_1,int>
110 >
111
112 [heading Template]
113
114 Does T have a nested class template called 'AMemberTemplate' whose template
115 parameters are all types ('class' or 'typename') ?
116
117 BOOST_TTI_HAS_TEMPLATE(AMemberTemplate,BOOST_PP_NIL)
118
119 has_template_AMemberTemplate
120 <
121 T
122 >
123
124 [heading Template using variadic macros]
125
126 Does T have a nested class template called 'AMemberTemplate' whose template
127 parameters are all types ('class' or 'typename') ?
128
129 BOOST_TTI_HAS_TEMPLATE(AnotherMemberTemplate)
130
131 has_template_AnotherMemberTemplate
132 <
133 T
134 >
135
136 [heading Template with params]
137
138 Does T have a nested class template called 'MoreParameters' whose template
139 parameters are specified exactly ?
140
141 BOOST_TTI_HAS_TEMPLATE(MoreParameters,(8,(class,class,int,short,class,template <class,int> class,class)))
142
143 has_template_MoreParameters
144 <
145 T
146 >
147
148 [heading Template with params using variadic macros]
149
150 Does T have a nested class template called 'ManyParameters' whose template
151 parameters are specified exactly ?
152
153 BOOST_TTI_HAS_TEMPLATE(ManyParameters,class,class,int,class,template <class> class,class,long)
154
155 has_template_ManyParameters
156 <
157 T
158 >
159
160 [heading Member data]
161
162 Does T have a member data called 'IntBT' whose type is 'AType::BType' ?
163
164 BOOST_TTI_HAS_MEMBER_DATA(IntBT)
165
166 has_member_data_IntBT
167 <
168 T,
169 AType::BType
170 >
171
172 [heading Member data with composite type]
173
174 Does T have a member data called 'IntBT' whose type is 'AType::BType' ?
175
176 BOOST_TTI_HAS_MEMBER_DATA(IntBT)
177
178 has_member_data_IntBT
179 <
180 AType::BType T::*
181 >
182
183 [heading Member function with individual types]
184
185 Does T have a member function called 'IntFunction' whose type is
186 'int (short)' ?
187
188 BOOST_TTI_HAS_MEMBER_FUNCTION(IntFunction)
189
190 has_member_function_IntFunction
191 <
192 T,
193 int,
194 boost::mpl::vector<short>
195 >
196
197 [heading Member function with composite type]
198
199 Does T have a member function called 'IntFunction' whose type is
200 'int (short)' ?
201
202 BOOST_TTI_HAS_MEMBER_FUNCTION(IntFunction)
203 has_member_function_IntFunction
204 <
205 int (T::*)(short)
206 >
207
208 [heading Static member data]
209
210 Does T have a static member data called 'DSMember' whose type is 'short' ?
211
212 BOOST_TTI_HAS_STATIC_MEMBER_DATA(DSMember)
213
214 has_static_member_data_DSMember
215 <
216 T,
217 short
218 >
219
220 [heading Static member function with individual types]
221
222 Does T have a static member function called 'SIntFunction' whose type
223 is 'int (long,double)' ?
224
225 BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION(SIntFunction)
226
227 has_static_member_function_SIntFunction
228 <
229 T,
230 int,
231 boost::mpl::vector<long,double>
232 >
233
234 [heading Static member function with composite type]
235
236 Does T have a static member function called 'SIntFunction' whose type
237 is 'int (long,double)' ?
238
239 BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION(SIntFunction)
240
241 has_static_member_function_SIntFunction
242 <
243 T,
244 int (long,double)
245 >
246
247 [heading Data]
248
249 Does T have a member data or static member data called 'DSMember' whose type is 'short' ?
250
251 BOOST_TTI_HAS_DATA(DSMember)
252
253 has_static_member_data_DSMember
254 <
255 T,
256 short
257 >
258
259 [heading Function]
260
261 Does T have a member function or a static member function called 'IntFunction' whose type is
262 'int (short)' ?
263
264 BOOST_TTI_HAS_FUNCTION(IntFunction)
265
266 has_function_IntFunction
267 <
268 T,
269 int,
270 boost::mpl::vector<short>
271 >
272
273 [heading Member type]
274
275 Create a nested type T::BType::CType without creating a compiler error
276 if T does not have the nested type BType::CType ?
277
278 BOOST_TTI_MEMBER_TYPE(BType)
279 BOOST_TTI_MEMBER_TYPE(CType)
280
281 typename
282 member_type_CType
283 <
284 typename
285 member_type_BType
286 <
287 T
288 >::type
289 >::type
290
291 [heading Member type existence]
292
293 Does a nested type T::BType::CType, created without creating a compiler error
294 if T does not have the nested type BType::CType, actually exist ?
295
296 BOOST_TTI_MEMBER_TYPE(BType)
297 BOOST_TTI_MEMBER_TYPE(CType)
298
299 typedef typename
300 member_type_CType
301 <
302 typename
303 member_type_BType
304 <
305 T
306 >::type
307 >::type
308 AType;
309
310 boost::tti::valid_member_type
311 <
312 AType
313 >
314
315 [endsect]