• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_UNION_HPP)
8 #define BOOST_TTI_HAS_UNION_HPP
9 
10 #include <boost/config.hpp>
11 #include <boost/preprocessor/cat.hpp>
12 #include <boost/tti/gen/has_union_gen.hpp>
13 #include <boost/tti/gen/namespace_gen.hpp>
14 #include <boost/tti/detail/dunion.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 union with a particular name exists.
27 /**
28 
29     BOOST_TTI_TRAIT_HAS_UNION is a macro which expands to a metafunction.
30     The metafunction tests whether an inner union with a particular name exists
31     and, optionally, whether an MPL lambda expression invoked with the inner union
32     is true or not. The macro takes the form of BOOST_TTI_TRAIT_HAS_UNION(trait,name) where
33 
34     trait = the name of the metafunction <br/>
35     name  = the name of the inner union.
36 
37     BOOST_TTI_TRAIT_HAS_UNION 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 union 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' union
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' union 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 union 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' union 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_UNION(LookFor,MyType) generates the metafunction LookFor in the current scope
78   to look for an inner union called MyType.
79 
80   LookFor<EnclosingType>::value is true if MyType is an inner union of EnclosingType, otherwise false.
81 
82   LookFor<EnclosingType,ALambdaExpression>::value is true if MyType is an inner union of EnclosingType
83     and invoking ALambdaExpression with the inner union returns a value of true, otherwise false.
84 
85   A popular use of the optional MPL lambda expression is to check whether the union found is the same
86   as another type, when the union 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 union
89     of EnclosingType and is the same type as SomeOtherType.
90 
91   @endcode
92 
93 */
94 #define BOOST_TTI_TRAIT_HAS_UNION(trait,name) \
95   BOOST_TTI_DETAIL_TRAIT_HAS_UNION(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_union)<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 union with a particular name exists.
110 /**
111 
112     BOOST_TTI_HAS_UNION is a macro which expands to a metafunction.
113     The metafunction tests whether an inner union with a particular name exists
114     and, optionally, whether an MPL lambda expression invoked with the inner union
115     is true or not. The macro takes the form of BOOST_TTI_HAS_UNION(name) where
116 
117     name  = the name of the inner union.
118 
119     BOOST_TTI_HAS_UNION generates a metafunction called "has_union_'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_union_'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 
134                 BOOST_TTI_TP_U = (optional) An optional template parameter, defaulting to a marker type.
135                                    If specified it is an MPL lambda expression which is invoked
136                                    with the inner union found and must return a constant boolean
137                                    value.
138 
139                 returns = 'value' depends on whether or not the optional BOOST_TTI_TP_U is specified.
140 
141                           If BOOST_TTI_TP_U is not specified, then 'value' is true if the 'name' union
142                           exists within the enclosing type BOOST_TTI_TP_T; otherwise 'value' is false.
143 
144                           If BOOST_TTI_TP_U is specified, then 'value' is true if the 'name' union exists
145                           within the enclosing type BOOST_TTI_TP_T and the MPL lambda expression as specified
146                           by BOOST_TTI_TP_U, invoked by passing the actual inner union of 'name', returns
147                           a 'value' of true; otherwise 'value' is false.
148 
149                           The action taken with BOOST_TTI_TP_U occurs only when the 'name' union exists
150                           within the enclosing type BOOST_TTI_TP_T.
151 
152   @endcode
153 
154   Example usage:
155 
156   @code
157 
158   BOOST_TTI_HAS_UNION(MyType) generates the metafunction has_union_MyType in the current scope
159   to look for an inner union called MyType.
160 
161   has_union_MyType<EnclosingType>::value is true if MyType is an inner union of EnclosingType, otherwise false.
162 
163   has_class_MyType<EnclosingType,ALambdaExpression>::value is true if MyType is an inner union of EnclosingType
164     and invoking ALambdaExpression with the inner union returns a value of true, otherwise false.
165 
166   A popular use of the optional MPL lambda expression is to check whether the union found is the same
167   as another type, when the union found is a typedef. In that case our example would be:
168 
169   has_union_MyType<EnclosingType,boost::is_same<_,SomeOtherType> >::value is true if MyType is an inner union
170     of EnclosingType and is the same type as SomeOtherType.
171 
172   @endcode
173 
174 */
175 #define BOOST_TTI_HAS_UNION(name) \
176   BOOST_TTI_TRAIT_HAS_UNION \
177   ( \
178   BOOST_TTI_HAS_UNION_GEN(name), \
179   name \
180   ) \
181 /**/
182 
183 #endif // BOOST_TTI_HAS_UNION_HPP
184