1.. Macros/Introspection//BOOST_MPL_HAS_XXX_TRAIT_DEF 2 3BOOST_MPL_HAS_XXX_TRAIT_DEF 4=========================== 5 6Synopsis 7-------- 8 9.. parsed-literal:: 10 11 #define BOOST_MPL_HAS_XXX_TRAIT_DEF(name) \\ 12 |unspecified-token-seq| \\ 13 /\*\*/ 14 15 16Description 17----------- 18 19Expands into a definition of a boolean unary |Metafunction| ``has_name`` 20such that for any type ``x`` ``has_name<x>::value == true`` if and only 21if ``x`` is a class type and has a nested type memeber ``x::name``. 22 23On the deficient compilers not capabale of performing the detection, 24``has_name<x>::value`` always returns ``false``. A boolean configuraion 25macro, |BOOST_MPL_CFG_NO_HAS_XXX|, is provided to signal or override 26the "deficient" status of a particular compiler. 27 28|Note:| |BOOST_MPL_HAS_XXX_TRAIT_DEF| is a simplified front end to 29the |BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF| introspection macro |-- end note| 30 31 32Header 33------ 34 35.. parsed-literal:: 36 37 #include <boost/mpl/has_xxx.hpp> 38 39 40Parameters 41---------- 42 43 44+---------------+-------------------------------+---------------------------------------------------+ 45| Parameter | Requirement | Description | 46+===============+===============================+===================================================+ 47| ``name`` | A legal identifier token | A name of the member being detected. | 48+---------------+-------------------------------+---------------------------------------------------+ 49 50 51Expression semantics 52-------------------- 53 54For any legal C++ identifier ``name``: 55 56.. parsed-literal:: 57 58 BOOST_MPL_HAS_XXX_TRAIT_DEF(name) 59 60:Precondition: 61 Appears at namespace scope. 62 63:Return type: 64 None. 65 66:Semantics: 67 Equivalent to 68 69 .. parsed-literal:: 70 71 BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF( 72 BOOST_PP_CAT(has\_,name), name, false 73 ) 74 75 76Example 77------- 78 79.. parsed-literal:: 80 81 BOOST_MPL_HAS_XXX_TRAIT_DEF(xxx) 82 83 struct test1 {}; 84 struct test2 { void xxx(); }; 85 struct test3 { int xxx; }; 86 struct test4 { static int xxx(); }; 87 struct test5 { template< typename T > struct xxx {}; }; 88 struct test6 { typedef int xxx; }; 89 struct test7 { struct xxx; }; 90 struct test8 { typedef void (\*xxx)(); }; 91 struct test9 { typedef void (xxx)(); }; 92 93 BOOST_MPL_ASSERT_NOT(( has_xxx<test1> )); 94 BOOST_MPL_ASSERT_NOT(( has_xxx<test2> )); 95 BOOST_MPL_ASSERT_NOT(( has_xxx<test3> )); 96 BOOST_MPL_ASSERT_NOT(( has_xxx<test4> )); 97 BOOST_MPL_ASSERT_NOT(( has_xxx<test5> )); 98 99 #if !defined(BOOST_MPL_CFG_NO_HAS_XXX) 100 BOOST_MPL_ASSERT(( has_xxx<test6> )); 101 BOOST_MPL_ASSERT(( has_xxx<test7> )); 102 BOOST_MPL_ASSERT(( has_xxx<test8> )); 103 BOOST_MPL_ASSERT(( has_xxx<test9> )); 104 #endif 105 106 BOOST_MPL_ASSERT(( has_xxx<test6,true\_> )); 107 BOOST_MPL_ASSERT(( has_xxx<test7,true\_> )); 108 BOOST_MPL_ASSERT(( has_xxx<test8,true\_> )); 109 BOOST_MPL_ASSERT(( has_xxx<test9,true\_> )); 110 111 112See also 113-------- 114 115|Macros|, |BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF|, |BOOST_MPL_CFG_NO_HAS_XXX| 116 117 118.. copyright:: Copyright � 2001-2009 Aleksey Gurtovoy and David Abrahams 119 Distributed under the Boost Software License, Version 1.0. (See accompanying 120 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 121