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