1.. Macros/Introspection//BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF
2
3BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF
4=================================
5
6Synopsis
7--------
8
9.. parsed-literal::
10
11    #define BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name, default\_) \\
12        |unspecified-token-seq| \\
13    /\*\*/
14
15
16Description
17-----------
18
19Expands into a definition of a boolean unary |Metafunction| ``trait``
20such that for any type ``x`` ``trait<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``trait<x>::value`` always returns a fallback value ``default_``.
25A boolean configuraion macro, |BOOST_MPL_CFG_NO_HAS_XXX|, is provided
26to signal or override the "deficient" status of a particular compiler.
27|Note:| The fallback value can also be provided at the point of the
28metafunction invocation; see the `Expression semantics` section for
29details |-- 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| 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+---------------+-------------------------------+---------------------------------------------------+
52
53
54Expression semantics
55--------------------
56
57For any legal C++ identifiers ``trait`` and ``name``, boolean constant expression ``c1``,
58boolean |Integral Constant| ``c2``, and arbitrary type ``x``:
59
60.. parsed-literal::
61
62    BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name, c1)
63
64:Precondition:
65    Appears at namespace scope.
66
67:Return type:
68    None.
69
70:Semantics:
71    Expands into an equivalent of the following class template definition
72
73    .. parsed-literal::
74
75        template< typename X, typename fallback = boost::mpl::bool_<c1> >
76        struct trait
77        {
78            // |unspecified|
79            // ...
80        };
81
82    where ``trait`` is a boolean |Metafunction| with the following semantics:
83
84    .. parsed-literal::
85
86        typedef trait<x>::type r;
87
88    :Return type:
89        |Integral Constant|.
90
91    :Semantics:
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``.
95
96
97    .. parsed-literal::
98
99        typedef trait< x,c2 >::type r;
100
101    :Return type:
102        |Integral Constant|.
103
104    :Semantics:
105        If |BOOST_MPL_CFG_NO_HAS_XXX| is defined, ``r::value == c2::value``;
106        otherwise, equivalent to
107
108        .. parsed-literal::
109
110            typedef trait<x>::type r;
111
112
113Example
114-------
115
116.. parsed-literal::
117
118    BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_xxx, xxx, false)
119
120    struct test1 {};
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)(); };
129
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> ));
135
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> ));
141    #endif
142
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\_> ));
147
148
149See also
150--------
151
152|Macros|, |BOOST_MPL_HAS_XXX_TRAIT_DEF|, |BOOST_MPL_CFG_NO_HAS_XXX|
153
154
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)
158