1 .. Macros/Introspection//BOOST_MPL_HAS_XXX_TRAIT_DEF
3 BOOST_MPL_HAS_XXX_TRAIT_DEF
4 ===========================
11 #define BOOST_MPL_HAS_XXX_TRAIT_DEF(name) \\
12 |unspecified-token-seq| \\
19 Expands into a definition of a boolean unary |Metafunction| ``has_name``
20 such that for any type ``x`` ``has_name<x>::value == true`` if and only
21 if ``x`` is a class type and has a nested type memeber ``x::name``.
23 On the deficient compilers not capabale of performing the detection,
24 ``has_name<x>::value`` always returns ``false``. A boolean configuraion
25 macro, |BOOST_MPL_CFG_NO_HAS_XXX|, is provided to signal or override
26 the "deficient" status of a particular compiler.
28 |Note:| |BOOST_MPL_HAS_XXX_TRAIT_DEF| is a simplified front end to
29 the |BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF| introspection macro |-- end note|
37 #include <boost/mpl/has_xxx.hpp>
44 +---------------+-------------------------------+---------------------------------------------------+
45 | Parameter | Requirement | Description |
46 +===============+===============================+===================================================+
47 | ``name`` | A legal identifier token | A name of the member being detected. |
48 +---------------+-------------------------------+---------------------------------------------------+
54 For any legal C++ identifier ``name``:
58 BOOST_MPL_HAS_XXX_TRAIT_DEF(name)
61 Appears at namespace scope.
71 BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(
72 BOOST_PP_CAT(has\_,name), name, false
81 BOOST_MPL_HAS_XXX_TRAIT_DEF(xxx)
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)(); };
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> ));
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> ));
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\_> ));
115 |Macros|, |BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF|, |BOOST_MPL_CFG_NO_HAS_XXX|
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)