1 .. Macros/Introspection//BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF
3 BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF
4 =================================
11 #define BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name, default\_) \\
12 |unspecified-token-seq| \\
19 Expands into a definition of a boolean unary |Metafunction| ``trait``
20 such that for any type ``x`` ``trait<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 ``trait<x>::value`` always returns a fallback value ``default_``.
25 A boolean configuraion macro, |BOOST_MPL_CFG_NO_HAS_XXX|, is provided
26 to signal or override the "deficient" status of a particular compiler.
27 |Note:| The fallback value can also be provided at the point of the
28 metafunction invocation; see the `Expression semantics` section for
37 #include <boost/mpl/has_xxx.hpp>
43 +---------------+-------------------------------+---------------------------------------------------+
44 | Parameter | Requirement | Description |
45 +===============+===============================+===================================================+
46 | ``trait`` | A legal identifier token | A name of the metafunction to be generated. |
47 +---------------+-------------------------------+---------------------------------------------------+
48 | ``name`` | A legal identifier token | A name of the member being detected. |
49 +---------------+-------------------------------+---------------------------------------------------+
50 | ``default_`` | An boolean constant | A fallback value for the deficient compilers. |
51 +---------------+-------------------------------+---------------------------------------------------+
57 For any legal C++ identifiers ``trait`` and ``name``, boolean constant expression ``c1``,
58 boolean |Integral Constant| ``c2``, and arbitrary type ``x``:
62 BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name, c1)
65 Appears at namespace scope.
71 Expands into an equivalent of the following class template definition
75 template< typename X, typename fallback = boost::mpl::bool_<c1> >
82 where ``trait`` is a boolean |Metafunction| with the following semantics:
86 typedef trait<x>::type r;
92 If |BOOST_MPL_CFG_NO_HAS_XXX| is defined, ``r::value == c1``;
93 otherwise, ``r::value == true`` if and only if ``x`` is a class type
94 that has a nested type memeber ``x::name``.
99 typedef trait< x,c2 >::type r;
105 If |BOOST_MPL_CFG_NO_HAS_XXX| is defined, ``r::value == c2::value``;
106 otherwise, equivalent to
110 typedef trait<x>::type r;
118 BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_xxx, xxx, false)
121 struct test2 { void xxx(); };
122 struct test3 { int xxx; };
123 struct test4 { static int xxx(); };
124 struct test5 { template< typename T > struct xxx {}; };
125 struct test6 { typedef int xxx; };
126 struct test7 { struct xxx; };
127 struct test8 { typedef void (\*xxx)(); };
128 struct test9 { typedef void (xxx)(); };
130 BOOST_MPL_ASSERT_NOT(( has_xxx<test1> ));
131 BOOST_MPL_ASSERT_NOT(( has_xxx<test2> ));
132 BOOST_MPL_ASSERT_NOT(( has_xxx<test3> ));
133 BOOST_MPL_ASSERT_NOT(( has_xxx<test4> ));
134 BOOST_MPL_ASSERT_NOT(( has_xxx<test5> ));
136 #if !defined(BOOST_MPL_CFG_NO_HAS_XXX)
137 BOOST_MPL_ASSERT(( has_xxx<test6> ));
138 BOOST_MPL_ASSERT(( has_xxx<test7> ));
139 BOOST_MPL_ASSERT(( has_xxx<test8> ));
140 BOOST_MPL_ASSERT(( has_xxx<test9> ));
143 BOOST_MPL_ASSERT(( has_xxx<test6,true\_> ));
144 BOOST_MPL_ASSERT(( has_xxx<test7,true\_> ));
145 BOOST_MPL_ASSERT(( has_xxx<test8,true\_> ));
146 BOOST_MPL_ASSERT(( has_xxx<test9,true\_> ));
152 |Macros|, |BOOST_MPL_HAS_XXX_TRAIT_DEF|, |BOOST_MPL_CFG_NO_HAS_XXX|
155 .. copyright:: Copyright © 2001-2009 Aleksey Gurtovoy and David Abrahams
156 Distributed under the Boost Software License, Version 1.0. (See accompanying
157 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)