]>
Commit | Line | Data |
---|---|---|
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_func_sig Nested Types and Function Signatures] | |
9 | ||
10 | The strength of `BOOST_TTI_MEMBER_TYPE` to represent a type which may or may not exist, and which | |
11 | then can be subsequently used in other macro metafunctions whenever a type is needed as a template | |
12 | parameter without producing a compiler error, should not be underestimated. It is one of the | |
13 | reasons why we have two different ways of using our generated metafunction when introspecting | |
14 | for member data, a member function, or a static member function of an enclosing type. | |
15 | ||
16 | In the cases where we specify a composite syntax when using `BOOST_TTI_HAS_MEMBER_DATA`, | |
17 | `BOOST_TTI_HAS_MEMBER_FUNCTION`, or `BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION`, the signature | |
18 | for the member data, member function, or static member function is a single type. For | |
19 | `BOOST_TTI_HAS_MEMBER_DATA` the signature is a pointer to member data, for | |
20 | `BOOST_TTI_HAS_MEMBER_FUNCTION` the signature is a pointer to a member function, and for | |
21 | `BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION` the signature is divided between an enclosing type | |
22 | and a function in composite format. This makes for a syntactical notation which is natural | |
23 | to specify, but because of the notation we can not use the nested type functionality in | |
24 | `BOOST_TTI_MEMBER_TYPE` for potential parts of these composite types. If any part of this | |
25 | signature, which specifies a composite of various types, is invalid, a compiler time error | |
26 | will occur. | |
27 | ||
28 | But in the more specific cases, when we use `BOOST_TTI_HAS_MEMBER_DATA`, | |
29 | `BOOST_TTI_HAS_MEMBER_FUNCTION`, and `BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION`, our composite | |
30 | type in our signatures is broken down into their individual types so that using | |
31 | `BOOST_TTI_MEMBER_TYPE` for any one of the individual types will not lead to a compile time | |
32 | error if the type specified does not actually exist. | |
33 | ||
34 | A few examples will suffice. | |
35 | ||
36 | Given known types T and U, and the supposed type Ntype as a | |
37 | nested type of U, we want to find out if type T has a member function whose signature is | |
38 | `void aMemberFunction(U::Ntype)`. | |
39 | ||
40 | First using `BOOST_TTI_HAS_MEMBER_FUNCTION` using our composite form we would code: | |
41 | ||
42 | #include <boost/tti/has_member_function.hpp> | |
43 | ||
44 | BOOST_TTI_HAS_MEMBER_FUNCTION(aMemberFunction) | |
45 | ||
46 | has_member_function_aMemberFunction<void (T::*)(U::Ntype)>::value; | |
47 | ||
48 | If the nested type U::Ntype does not exist, this leads to a compiler error. | |
49 | We really want to avoid this situation, so let's try our alternative. | |
50 | ||
51 | Second using `BOOST_TTI_HAS_MEMBER_FUNCTION` using our specific form we would code: | |
52 | ||
53 | #include <boost/tti/member_type.hpp> | |
54 | #include <boost/tti/has_member_function.hpp> | |
55 | ||
56 | BOOST_TTI_HAS_MEMBER_TYPE(Ntype) | |
57 | BOOST_TTI_HAS_MEMBER_FUNCTION(aMemberFunction) | |
58 | ||
59 | typedef typename has_member_type_Ntype<U>::type OurType; | |
60 | has_member_function_aMemberFunction<T,void,boost::mpl::vector<OurType> >::value; | |
61 | ||
62 | If the nested type U::Ntype does exist and T does have a member function | |
63 | whose signature is `void aMemberFunction(U::Ntype)` our 'value' is true, | |
64 | otherwise it is false. We will never get a compiler error in this case. | |
65 | ||
66 | As a second example we will once again use the suppositions of our first | |
67 | example; given known types T and U, and the supposed type Ntype as a | |
68 | nested type of U. But this time let us look for a static member function | |
69 | whose signature is `void aStaticMemberFunction(U::Ntype)`. | |
70 | ||
71 | First using `BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION` using our composite form we would code: | |
72 | ||
73 | #include <boost/tti/has_static_member_function.hpp> | |
74 | ||
75 | BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION(aStaticMemberFunction) | |
76 | ||
77 | has_static_member_function_aStaticMemberFunction<T,void (U::Ntype)>::value; | |
78 | ||
79 | Once again if the nested type U::Ntype does not exist, this leads to a compiler error, | |
80 | so let's try our alternative. | |
81 | ||
82 | Second using `BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION` using our specific form we would code: | |
83 | ||
84 | #include <boost/tti/member_type.hpp> | |
85 | #include <boost/tti/has_static_member_function.hpp> | |
86 | ||
87 | BOOST_TTI_HAS_MEMBER_TYPE(Ntype) | |
88 | BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION(aStaticMemberFunction) | |
89 | ||
90 | typedef typename has_member_type_Ntype<U>::type OurType; | |
91 | has_static_member_function_aStaticMemberFunction<T,void,boost::mpl::vector<OurType> >::value; | |
92 | ||
93 | If the nested type U::Ntype does exist and T does have a member function | |
94 | whose signature is `void aMemberFunction(U::Ntype)` our 'value' is true, | |
95 | otherwise it is false. We will never get a compiler error in this case. | |
96 | ||
97 | [endsect] |