|
||||
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_ENUM_HPP) 0008 #define BOOST_TTI_HAS_ENUM_HPP 0009 0010 #include <boost/config.hpp> 0011 #include <boost/preprocessor/cat.hpp> 0012 #include <boost/tti/gen/has_enum_gen.hpp> 0013 #include <boost/tti/gen/namespace_gen.hpp> 0014 #include <boost/tti/detail/denum.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 enum with a particular name exists. 0027 /** 0028 0029 BOOST_TTI_TRAIT_HAS_ENUM is a macro which expands to a metafunction. 0030 The metafunction tests whether an inner enum with a particular name exists 0031 and, optionally, whether an MPL lambda expression invoked with the inner enum 0032 is true or not. The macro takes the form of BOOST_TTI_TRAIT_HAS_ENUM(trait,name) where 0033 0034 trait = the name of the metafunction <br/> 0035 name = the name of the inner enum. The name can be that of an enum or, in C++11 on up, an enum class. 0036 0037 BOOST_TTI_TRAIT_HAS_ENUM 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 enum 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' enum 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' enum 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 enum 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' enum 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_ENUM(LookFor,MyType) generates the metafunction LookFor in the current scope 0078 to look for an inner enum called MyType. 0079 0080 LookFor<EnclosingType>::value is true if MyType is an inner enum of EnclosingType, otherwise false. 0081 0082 LookFor<EnclosingType,ALambdaExpression>::value is true if MyType is an inner enum of EnclosingType 0083 and invoking ALambdaExpression with the inner enum returns a value of true, otherwise false. 0084 0085 A popular use of the optional MPL lambda expression is to check whether the enum found is the same 0086 as another type, when the enum 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 enum 0089 of EnclosingType and is the same type as SomeOtherType. 0090 0091 @endcode 0092 0093 */ 0094 #define BOOST_TTI_TRAIT_HAS_ENUM(trait,name) \ 0095 BOOST_TTI_DETAIL_TRAIT_HAS_ENUM(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_enum)<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 enum with a particular name exists. 0110 /** 0111 0112 BOOST_TTI_HAS_ENUM is a macro which expands to a metafunction. 0113 The metafunction tests whether an inner enum with a particular name exists 0114 and, optionally, whether an MPL lambda expression invoked with the inner enum 0115 is true or not. The macro takes the form of BOOST_TTI_HAS_ENUM(name) where 0116 0117 name = the name of the inner enum. The name can be that of an enum or, in C++11 on up, an enum class. 0118 0119 BOOST_TTI_HAS_ENUM generates a metafunction called "has_enum_'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_enum_'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 The enclosing type can be a class, struct, or union. 0134 0135 BOOST_TTI_TP_U = (optional) An optional template parameter, defaulting to a marker type. 0136 If specified it is an MPL lambda expression which is invoked 0137 with the inner enum found and must return a constant boolean 0138 value. 0139 0140 returns = 'value' depends on whether or not the optional BOOST_TTI_TP_U is specified. 0141 0142 If BOOST_TTI_TP_U is not specified, then 'value' is true if the 'name' enum 0143 exists within the enclosing type BOOST_TTI_TP_T; otherwise 'value' is false. 0144 0145 If BOOST_TTI_TP_U is specified, then 'value' is true if the 'name' enum exists 0146 within the enclosing type BOOST_TTI_TP_T and the MPL lambda expression as specified 0147 by BOOST_TTI_TP_U, invoked by passing the actual inner enum of 'name', returns 0148 a 'value' of true; otherwise 'value' is false. 0149 0150 The action taken with BOOST_TTI_TP_U occurs only when the 'name' enum exists 0151 within the enclosing type BOOST_TTI_TP_T. 0152 0153 @endcode 0154 0155 Example usage: 0156 0157 @code 0158 0159 BOOST_TTI_HAS_ENUM(MyType) generates the metafunction has_enum_MyType in the current scope 0160 to look for an inner enum called MyType. 0161 0162 has_enum_MyType<EnclosingType>::value is true if MyType is an inner enum of EnclosingType, otherwise false. 0163 0164 has_class_MyType<EnclosingType,ALambdaExpression>::value is true if MyType is an inner enum of EnclosingType 0165 and invoking ALambdaExpression with the inner enum returns a value of true, otherwise false. 0166 0167 A popular use of the optional MPL lambda expression is to check whether the enum found is the same 0168 as another type, when the enum found is a typedef. In that case our example would be: 0169 0170 has_enum_MyType<EnclosingType,boost::is_same<_,SomeOtherType> >::value is true if MyType is an inner enum 0171 of EnclosingType and is the same type as SomeOtherType. 0172 0173 @endcode 0174 0175 */ 0176 #define BOOST_TTI_HAS_ENUM(name) \ 0177 BOOST_TTI_TRAIT_HAS_ENUM \ 0178 ( \ 0179 BOOST_TTI_HAS_ENUM_GEN(name), \ 0180 name \ 0181 ) \ 0182 /**/ 0183 0184 #endif // BOOST_TTI_HAS_ENUM_HPP
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |