// (C) Copyright Edward Diener 2019 // Use, modification and distribution are subject to the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt). #if !defined(ACTIV_BOOST_TTI_HAS_ENUM_HPP) #define ACTIV_BOOST_TTI_HAS_ENUM_HPP #include #include #include #include #include #include /* The succeeding comments in this file are in doxygen format. */ /** \file */ /// A macro which expands to a metafunction which tests whether an inner enum with a particular name exists. /** ACTIV_BOOST_TTI_TRAIT_HAS_ENUM is a macro which expands to a metafunction. The metafunction tests whether an inner enum with a particular name exists and, optionally, whether an MPL lambda expression invoked with the inner enum is true or not. The macro takes the form of ACTIV_BOOST_TTI_TRAIT_HAS_ENUM(trait,name) where trait = the name of the metafunction
name = the name of the inner enum. The name can be that of an enum or, in C++11 on up, an enum class. ACTIV_BOOST_TTI_TRAIT_HAS_ENUM generates a metafunction called "trait" where 'trait' is the macro parameter. @code template struct trait { static const value = unspecified; typedef mpl::bool_ type; }; The metafunction types and return: ACTIV_BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'. The enclosing type can be a class, struct, or union. ACTIV_BOOST_TTI_TP_U = (optional) An optional template parameter, defaulting to a marker type. If specified it is an MPL lambda expression which is invoked with the inner enum found and must return a constant boolean value. returns = 'value' depends on whether or not the optional ACTIV_BOOST_TTI_TP_U is specified. If ACTIV_BOOST_TTI_TP_U is not specified, then 'value' is true if the 'name' enum exists within the enclosing type ACTIV_BOOST_TTI_TP_T; otherwise 'value' is false. If ACTIV_BOOST_TTI_TP_U is specified , then 'value' is true if the 'name' enum exists within the enclosing type ACTIV_BOOST_TTI_TP_T and the MPL lambda expression as specified by ACTIV_BOOST_TTI_TP_U, invoked by passing the actual inner enum of 'name', returns a 'value' of true; otherwise 'value' is false. The action taken with ACTIV_BOOST_TTI_TP_U occurs only when the 'name' enum exists within the enclosing type ACTIV_BOOST_TTI_TP_T. @endcode Example usage: @code ACTIV_BOOST_TTI_TRAIT_HAS_ENUM(LookFor,MyType) generates the metafunction LookFor in the current scope to look for an inner enum called MyType. LookFor::value is true if MyType is an inner enum of EnclosingType, otherwise false. LookFor::value is true if MyType is an inner enum of EnclosingType and invoking ALambdaExpression with the inner enum returns a value of true, otherwise false. A popular use of the optional MPL lambda expression is to check whether the enum found is the same as another type, when the enum found is a typedef. In that case our example would be: LookFor >::value is true if MyType is an inner enum of EnclosingType and is the same type as SomeOtherType. @endcode */ #define ACTIV_BOOST_TTI_TRAIT_HAS_ENUM(trait,name) \ ACTIV_BOOST_TTI_DETAIL_TRAIT_HAS_ENUM(trait,name) \ template \ < \ class ACTIV_BOOST_TTI_TP_T, \ class ACTIV_BOOST_TTI_TP_U = ACTIV_BOOST_TTI_NAMESPACE::detail::deftype \ > \ struct trait \ { \ typedef typename \ ACTIV_BOOST_PP_CAT(trait,_detail_enum)::type type; \ ACTIV_BOOST_STATIC_CONSTANT(bool,value=type::value); \ }; \ /**/ /// A macro which expands to a metafunction which tests whether an inner enum with a particular name exists. /** ACTIV_BOOST_TTI_HAS_ENUM is a macro which expands to a metafunction. The metafunction tests whether an inner enum with a particular name exists and, optionally, whether an MPL lambda expression invoked with the inner enum is true or not. The macro takes the form of ACTIV_BOOST_TTI_HAS_ENUM(name) where name = the name of the inner enum. The name can be that of an enum or, in C++11 on up, an enum class. ACTIV_BOOST_TTI_HAS_ENUM generates a metafunction called "has_enum_'name'" where 'name' is the macro parameter. @code template struct has_enum_'name' { static const value = unspecified; typedef mpl::bool_ type; }; The metafunction types and return: ACTIV_BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'. The enclosing type can be a class, struct, or union. ACTIV_BOOST_TTI_TP_U = (optional) An optional template parameter, defaulting to a marker type. If specified it is an MPL lambda expression which is invoked with the inner enum found and must return a constant boolean value. returns = 'value' depends on whether or not the optional ACTIV_BOOST_TTI_TP_U is specified. If ACTIV_BOOST_TTI_TP_U is not specified, then 'value' is true if the 'name' enum exists within the enclosing type ACTIV_BOOST_TTI_TP_T; otherwise 'value' is false. If ACTIV_BOOST_TTI_TP_U is specified, then 'value' is true if the 'name' enum exists within the enclosing type ACTIV_BOOST_TTI_TP_T and the MPL lambda expression as specified by ACTIV_BOOST_TTI_TP_U, invoked by passing the actual inner enum of 'name', returns a 'value' of true; otherwise 'value' is false. The action taken with ACTIV_BOOST_TTI_TP_U occurs only when the 'name' enum exists within the enclosing type ACTIV_BOOST_TTI_TP_T. @endcode Example usage: @code ACTIV_BOOST_TTI_HAS_ENUM(MyType) generates the metafunction has_enum_MyType in the current scope to look for an inner enum called MyType. has_enum_MyType::value is true if MyType is an inner enum of EnclosingType, otherwise false. has_class_MyType::value is true if MyType is an inner enum of EnclosingType and invoking ALambdaExpression with the inner enum returns a value of true, otherwise false. A popular use of the optional MPL lambda expression is to check whether the enum found is the same as another type, when the enum found is a typedef. In that case our example would be: has_enum_MyType >::value is true if MyType is an inner enum of EnclosingType and is the same type as SomeOtherType. @endcode */ #define ACTIV_BOOST_TTI_HAS_ENUM(name) \ ACTIV_BOOST_TTI_TRAIT_HAS_ENUM \ ( \ ACTIV_BOOST_TTI_HAS_ENUM_GEN(name), \ name \ ) \ /**/ #endif // ACTIV_BOOST_TTI_HAS_ENUM_HPP