]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/tti/doc/tti_detail_has_data.qbk
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / tti / doc / tti_detail_has_data.qbk
1 [/
2 (C) Copyright Edward Diener 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_detail_has_data Introspecting inner data]
9
10 The TTI macro [macroref BOOST_TTI_HAS_DATA] introspects the data of a class.
11 The data can be member data or static member data.
12
13 BOOST_TTI_HAS_DATA macro takes a single parameter, which is the name
14 of an inner member data or static member data, whose existence
15 the programmer wants to check. The macro generates a metafunction
16 called 'has_data_'name_of_inner_data'.
17
18 The metafunction can be invoked by passing it the enclosing type
19 to introspect and the type of the data.
20
21 The metafunction returns a single type called 'type', which is a
22 boost::mpl::bool_. As a convenience the metafunction
23 returns the value of this type directly as a compile time bool constant
24 called 'value'. This is true or false depending on whether the inner
25 data, of the specified type, exists or not.
26
27 [heading Generating the metafunction]
28
29 You generate the metafunction by invoking the macro with the name
30 of an inner data member:
31
32 BOOST_TTI_HAS_DATA(AData)
33
34 generates a metafunction called 'has_data_AStaticMemberData' in the current scope.
35
36 [heading Invoking the metafunction]
37
38 You invoke the metafunction by instantiating the template with an enclosing
39 type to introspect and the type of the data. A return value called
40 'value' is a compile time bool constant.
41
42 has_data_AData<Enclosing_Type,Data_Type>::value
43
44 [heading Examples]
45
46 First we generate metafunctions for various inner data names:
47
48 #include <boost/tti/has_data.hpp>
49
50 BOOST_TTI_HAS_DATA(data1)
51 BOOST_TTI_HAS_DATA(data2)
52 BOOST_TTI_HAS_DATA(data3)
53
54 Next let us create some user-defined types we want to introspect.
55
56 struct AClass
57 {
58 };
59 struct Top
60 {
61 int data1;
62 static AClass * data2;
63 };
64 struct Top2
65 {
66 static long data1;
67 Top data3;
68 };
69
70 Finally we invoke our metafunction and return our value.
71 This all happens at compile time, and can be used by
72 programmers doing compile time template metaprogramming.
73
74 has_data_data1<Top,int>::value; // true
75 has_data_data1<Top,long>::value; // false
76 has_data_data1<Top2,int>::value; // false
77 has_data_data1<Top2,long>::value; // true
78
79 has_data_data2<Top,AClass *>::value; // true
80 has_data_data2<Top,int *>::value; // false
81
82 has_data_data3<Top2,int>::value; // false
83 has_data_data3<Top2,Top>::value; // true;
84
85 [heading Metafunction re-use]
86
87 The macro encodes only the name of the data for
88 which we are searching and the fact that we are introspecting
89 for data within an enclosing type.
90
91 Because of this, once we create our metafunction for
92 introspecting an inner data by name, we can reuse
93 the metafunction for introspecting any enclosing type, having
94 any inner data type, for that name.
95
96 [endsect]