Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:52:55

0001 
0002 //  (C) Copyright Edward Diener 2019
0003 //  Use, modification and distribution are subject to the Boost Software License,
0004 //  Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0005 //  http://www.boost.org/LICENSE_1_0.txt).
0006 
0007 #if !defined(BOOST_TTI_HAS_UNION_HPP)
0008 #define BOOST_TTI_HAS_UNION_HPP
0009 
0010 #include <boost/config.hpp>
0011 #include <boost/preprocessor/cat.hpp>
0012 #include <boost/tti/gen/has_union_gen.hpp>
0013 #include <boost/tti/gen/namespace_gen.hpp>
0014 #include <boost/tti/detail/dunion.hpp>
0015 #include <boost/tti/detail/ddeftype.hpp>
0016 
0017 /*
0018 
0019   The succeeding comments in this file are in doxygen format.
0020 
0021 */
0022 
0023 /** \file
0024 */
0025 
0026 /// A macro which expands to a metafunction which tests whether an inner union with a particular name exists.
0027 /**
0028 
0029     BOOST_TTI_TRAIT_HAS_UNION is a macro which expands to a metafunction.
0030     The metafunction tests whether an inner union with a particular name exists
0031     and, optionally, whether an MPL lambda expression invoked with the inner union
0032     is true or not. The macro takes the form of BOOST_TTI_TRAIT_HAS_UNION(trait,name) where
0033     
0034     trait = the name of the metafunction <br/>
0035     name  = the name of the inner union.
0036 
0037     BOOST_TTI_TRAIT_HAS_UNION generates a metafunction called "trait" where 'trait' is the macro parameter.
0038     
0039   @code
0040   
0041               template<class BOOST_TTI_TP_T,class BOOST_TTI_TP_U>
0042               struct trait
0043                 {
0044                 static const value = unspecified;
0045                 typedef mpl::bool_<true-or-false> type;
0046                 };
0047 
0048               The metafunction types and return:
0049     
0050                 BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'.
0051                                  The enclosing type can be a class, struct, or union.
0052                 
0053                 BOOST_TTI_TP_U = (optional) An optional template parameter, defaulting to a marker type.
0054                                    If specified it is an MPL lambda expression which is invoked 
0055                                    with the inner union found and must return a constant boolean 
0056                                    value.
0057                                    
0058                 returns = 'value' depends on whether or not the optional BOOST_TTI_TP_U is specified.
0059                 
0060                           If BOOST_TTI_TP_U is not specified, then 'value' is true if the 'name' union
0061                           exists within the enclosing type BOOST_TTI_TP_T; otherwise 'value' is false.
0062                           
0063                           If BOOST_TTI_TP_U is specified , then 'value' is true if the 'name' union exists 
0064                           within the enclosing type BOOST_TTI_TP_T and the MPL lambda expression as specified 
0065                           by BOOST_TTI_TP_U, invoked by passing the actual inner union of 'name', returns 
0066                           a 'value' of true; otherwise 'value' is false.
0067                              
0068                           The action taken with BOOST_TTI_TP_U occurs only when the 'name' union exists 
0069                           within the enclosing type BOOST_TTI_TP_T.
0070                              
0071   @endcode
0072   
0073   Example usage:
0074   
0075   @code
0076   
0077   BOOST_TTI_TRAIT_HAS_UNION(LookFor,MyType) generates the metafunction LookFor in the current scope
0078   to look for an inner union called MyType.
0079   
0080   LookFor<EnclosingType>::value is true if MyType is an inner union of EnclosingType, otherwise false.
0081   
0082   LookFor<EnclosingType,ALambdaExpression>::value is true if MyType is an inner union of EnclosingType
0083     and invoking ALambdaExpression with the inner union returns a value of true, otherwise false.
0084     
0085   A popular use of the optional MPL lambda expression is to check whether the union found is the same  
0086   as another type, when the union found is a typedef. In that case our example would be:
0087   
0088   LookFor<EnclosingType,boost::is_same<_,SomeOtherType> >::value is true if MyType is an inner union
0089     of EnclosingType and is the same type as SomeOtherType.
0090   
0091   @endcode
0092   
0093 */
0094 #define BOOST_TTI_TRAIT_HAS_UNION(trait,name) \
0095   BOOST_TTI_DETAIL_TRAIT_HAS_UNION(trait,name) \
0096   template \
0097     < \
0098     class BOOST_TTI_TP_T, \
0099     class BOOST_TTI_TP_U = BOOST_TTI_NAMESPACE::detail::deftype \
0100     > \
0101   struct trait \
0102     { \
0103     typedef typename \
0104     BOOST_PP_CAT(trait,_detail_union)<BOOST_TTI_TP_T,BOOST_TTI_TP_U>::type type; \
0105     BOOST_STATIC_CONSTANT(bool,value=type::value); \
0106     }; \
0107 /**/
0108 
0109 /// A macro which expands to a metafunction which tests whether an inner union with a particular name exists.
0110 /**
0111 
0112     BOOST_TTI_HAS_UNION is a macro which expands to a metafunction.
0113     The metafunction tests whether an inner union with a particular name exists
0114     and, optionally, whether an MPL lambda expression invoked with the inner union 
0115     is true or not. The macro takes the form of BOOST_TTI_HAS_UNION(name) where
0116     
0117     name  = the name of the inner union.
0118 
0119     BOOST_TTI_HAS_UNION generates a metafunction called "has_union_'name'" where 'name' is the macro parameter.
0120     
0121   @code
0122   
0123               template<class BOOST_TTI_TP_T,class BOOST_TTI_TP_U>
0124               struct has_union_'name'
0125                 {
0126                 static const value = unspecified;
0127                 typedef mpl::bool_<true-or-false> type;
0128                 };
0129 
0130               The metafunction types and return:
0131     
0132                 BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'.
0133                 
0134                 BOOST_TTI_TP_U = (optional) An optional template parameter, defaulting to a marker type.
0135                                    If specified it is an MPL lambda expression which is invoked 
0136                                    with the inner union found and must return a constant boolean 
0137                                    value.
0138                                    
0139                 returns = 'value' depends on whether or not the optional BOOST_TTI_TP_U is specified.
0140                 
0141                           If BOOST_TTI_TP_U is not specified, then 'value' is true if the 'name' union 
0142                           exists within the enclosing type BOOST_TTI_TP_T; otherwise 'value' is false.
0143                           
0144                           If BOOST_TTI_TP_U is specified, then 'value' is true if the 'name' union exists 
0145                           within the enclosing type BOOST_TTI_TP_T and the MPL lambda expression as specified 
0146                           by BOOST_TTI_TP_U, invoked by passing the actual inner union of 'name', returns 
0147                           a 'value' of true; otherwise 'value' is false.
0148                              
0149                           The action taken with BOOST_TTI_TP_U occurs only when the 'name' union exists 
0150                           within the enclosing type BOOST_TTI_TP_T.
0151                              
0152   @endcode
0153   
0154   Example usage:
0155   
0156   @code
0157   
0158   BOOST_TTI_HAS_UNION(MyType) generates the metafunction has_union_MyType in the current scope
0159   to look for an inner union called MyType.
0160   
0161   has_union_MyType<EnclosingType>::value is true if MyType is an inner union of EnclosingType, otherwise false.
0162   
0163   has_class_MyType<EnclosingType,ALambdaExpression>::value is true if MyType is an inner union of EnclosingType
0164     and invoking ALambdaExpression with the inner union returns a value of true, otherwise false.
0165   
0166   A popular use of the optional MPL lambda expression is to check whether the union found is the same  
0167   as another type, when the union found is a typedef. In that case our example would be:
0168   
0169   has_union_MyType<EnclosingType,boost::is_same<_,SomeOtherType> >::value is true if MyType is an inner union
0170     of EnclosingType and is the same type as SomeOtherType.
0171   
0172   @endcode
0173   
0174 */
0175 #define BOOST_TTI_HAS_UNION(name) \
0176   BOOST_TTI_TRAIT_HAS_UNION \
0177   ( \
0178   BOOST_TTI_HAS_UNION_GEN(name), \
0179   name \
0180   ) \
0181 /**/
0182 
0183 #endif // BOOST_TTI_HAS_UNION_HPP