Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/mpl/doc/refmanual/has-xxx-trait-named-def.html @ 45

Last change on this file since 45 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 12.0 KB
Line 
1<?xml version="1.0" encoding="utf-8" ?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4<!-- Copyright Aleksey Gurtovoy 2006. Distributed under the Boost -->
5<!-- Software License, Version 1.0. (See accompanying -->
6<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
7<head>
8<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
9<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
10<title>The MPL Reference Manual: BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF</title>
11<link rel="stylesheet" href="../style.css" type="text/css" />
12</head>
13<body class="docframe refmanual">
14<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./has-xxx-trait-def.html" class="navigation-link">Prev</a>&nbsp;<a href="./configuration.html" class="navigation-link">Next</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./has-xxx-trait-def.html" class="navigation-link">Back</a>&nbsp;Along</span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./introspection.html" class="navigation-link">Up</a>&nbsp;<a href="../refmanual.html" class="navigation-link">Home</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./refmanual_toc.html" class="navigation-link">Full TOC</a></span></td>
15<td class="header-group page-location"><a href="../refmanual.html" class="navigation-link">Front Page</a> / <a href="./macros.html" class="navigation-link">Macros</a> / <a href="./introspection.html" class="navigation-link">Introspection</a> / <a href="./has-xxx-trait-named-def.html" class="navigation-link">BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF</a></td>
16</tr></table><div class="header-separator"></div>
17<div class="section" id="has-xxx-trait-named-def">
18<h1><a class="toc-backref" href="./introspection.html#id517" name="has-xxx-trait-named-def">BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF</a></h1>
19<div class="section" id="macros-introspection-has-synopsis">
20<h3><a class="subsection-title" href="#synopsis" name="synopsis">Synopsis</a></h3>
21<pre class="literal-block">
22#define <a href="./has-xxx-trait-named-def.html" class="identifier">BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF</a>(trait, name, default_) \
23    <em>unspecified token sequence</em> \
24/**/
25</pre>
26</div>
27<div class="section" id="macros-introspection-has-description">
28<h3><a class="subsection-title" href="#description" name="description">Description</a></h3>
29<p>Expands into a definition of a boolean unary <a class="reference" href="./metafunction.html">Metafunction</a> <tt class="literal"><span class="pre">trait</span></tt> 
30such that for any type <tt class="literal"><span class="pre">x</span></tt> <tt class="literal"><span class="pre">trait&lt;x&gt;::value</span> <span class="pre">==</span> <span class="pre">true</span></tt> if and only
31if <tt class="literal"><span class="pre">x</span></tt> is a class type and has a nested type memeber <tt class="literal"><span class="pre">x::name</span></tt>.</p>
32<p>On the deficient compilers not capabale of performing the detection,
33<tt class="literal"><span class="pre">trait&lt;x&gt;::value</span></tt> always returns a fallback value <tt class="literal"><span class="pre">default_</span></tt>.
34A boolean configuraion macro, <a class="refentry reference" href="./cfg-no-has-xxx.html"><tt class="refentry literal"><span class="pre">BOOST_MPL_CFG_NO_HAS_XXX</span></tt></a>, is provided
35to signal or override the &quot;deficient&quot; status of a particular compiler.
36[<em>Note:</em> The fallback value call also be provided at the point of the
37metafunction invocation; see the <cite>Expression semantics</cite> section for
38details — <em>end note</em>]</p>
39</div>
40<div class="section" id="macros-introspection-has-header">
41<h3><a class="subsection-title" href="#header" name="header">Header</a></h3>
42<pre class="literal-block">
43#include &lt;<a href="../../../../boost/mpl/has_xxx.hpp" class="header">boost/mpl/has_xxx.hpp</a>&gt;
44</pre>
45</div>
46<div class="section" id="macros-introspection-has-parameters">
47<h3><a class="subsection-title" href="#parameters" name="parameters">Parameters</a></h3>
48<table border="1" class="table">
49<colgroup>
50<col width="15%" />
51<col width="32%" />
52<col width="53%" />
53</colgroup>
54<thead valign="bottom">
55<tr><th>Parameter</th>
56<th>Requirement</th>
57<th>Description</th>
58</tr>
59</thead>
60<tbody valign="top">
61<tr><td><tt class="literal"><span class="pre">trait</span></tt></td>
62<td>A legal identifier token</td>
63<td>A name of the metafunction to be generated.</td>
64</tr>
65<tr><td><tt class="literal"><span class="pre">name</span></tt></td>
66<td>A legal identifier token</td>
67<td>A name of the member being detected.</td>
68</tr>
69<tr><td><tt class="literal"><span class="pre">default_</span></tt></td>
70<td>An boolean constant</td>
71<td>A fallback value for the deficient compilers.</td>
72</tr>
73</tbody>
74</table>
75</div>
76<div class="section" id="macros-introspection-has-expression-semantics">
77<h3><a class="subsection-title" href="#expression-semantics" name="expression-semantics">Expression semantics</a></h3>
78<p>For any legal C++ identifiers <tt class="literal"><span class="pre">trait</span></tt> and <tt class="literal"><span class="pre">name</span></tt>, boolean constant expression <tt class="literal"><span class="pre">c1</span></tt>,
79boolean <a class="reference" href="./integral-constant.html">Integral Constant</a> <tt class="literal"><span class="pre">c2</span></tt>, and arbitrary type <tt class="literal"><span class="pre">x</span></tt>:</p>
80<pre class="literal-block">
81<a href="./has-xxx-trait-named-def.html" class="identifier">BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF</a>(trait, name, c1)
82</pre>
83<table class="field-list" frame="void" rules="none">
84<col class="field-name" />
85<col class="field-body" />
86<tbody valign="top">
87<tr class="field"><th class="field-name">Precondition:</th><td class="field-body">Appears at namespace scope.</td>
88</tr>
89<tr class="field"><th class="field-name">Return type:</th><td class="field-body">None.</td>
90</tr>
91<tr class="field"><th class="field-name">Semantics:</th><td class="field-body"><p class="first">Expands into an equivalent of the following class template definition</p>
92<pre class="literal-block">
93template&lt; typename X, typename fallback = boost::mpl::<a href="./bool.html" class="identifier">bool_</a>&lt;c1&gt; &gt;
94struct trait
95{
96    // <em>unspecified</em>
97    // ...
98};
99</pre>
100<p>where <tt class="literal"><span class="pre">trait</span></tt> is a boolean <a class="reference" href="./metafunction.html">Metafunction</a> with the following semantics:</p>
101<pre class="literal-block">
102typedef trait&lt;x&gt;::type r;
103</pre>
104<table class="field-list" frame="void" rules="none">
105<col class="field-name" />
106<col class="field-body" />
107<tbody valign="top">
108<tr class="field"><th class="field-name">Return type:</th><td class="field-body"><a class="reference" href="./integral-constant.html">Integral Constant</a>.</td>
109</tr>
110<tr class="field"><th class="field-name">Semantics:</th><td class="field-body">If <a class="refentry reference" href="./cfg-no-has-xxx.html"><tt class="refentry literal"><span class="pre">BOOST_MPL_CFG_NO_HAS_XXX</span></tt></a> is defined, <tt class="literal"><span class="pre">r::value</span> <span class="pre">==</span> <span class="pre">c1</span></tt>;
111otherwise, <tt class="literal"><span class="pre">r::value</span> <span class="pre">==</span> <span class="pre">true</span></tt> if and only if <tt class="literal"><span class="pre">x</span></tt> is a class type
112that has a nested type memeber <tt class="literal"><span class="pre">x::name</span></tt>.</td>
113</tr>
114</tbody>
115</table>
116<pre class="literal-block">
117typedef trait&lt; x,c2 &gt;::type r;
118</pre>
119<table class="last field-list" frame="void" rules="none">
120<col class="field-name" />
121<col class="field-body" />
122<tbody valign="top">
123<tr class="field"><th class="field-name">Return type:</th><td class="field-body"><a class="reference" href="./integral-constant.html">Integral Constant</a>.</td>
124</tr>
125<tr class="field"><th class="field-name">Semantics:</th><td class="field-body"><p class="first">If <a class="refentry reference" href="./cfg-no-has-xxx.html"><tt class="refentry literal"><span class="pre">BOOST_MPL_CFG_NO_HAS_XXX</span></tt></a> is defined, <tt class="literal"><span class="pre">r::value</span> <span class="pre">==</span> <span class="pre">c2::value</span></tt>;
126otherwise, equivalent to</p>
127<pre class="last literal-block">
128typedef trait&lt;x&gt;::type r;
129</pre>
130</td>
131</tr>
132</tbody>
133</table>
134</td>
135</tr>
136</tbody>
137</table>
138</div>
139<div class="section" id="macros-introspection-has-example">
140<h3><a class="subsection-title" href="#example" name="example">Example</a></h3>
141<pre class="literal-block">
142<a href="./has-xxx-trait-named-def.html" class="identifier">BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF</a>(has_xxx, xxx, false)
143
144struct test1 {};
145struct test2 { void xxx(); };
146struct test3 { int xxx; };
147struct test4 { static int xxx(); };
148struct test5 { template&lt; typename T &gt; struct xxx {}; };
149struct test6 { typedef int xxx; };
150struct test7 { struct xxx; };
151struct test8 { typedef void (*xxx)(); };
152struct test9 { typedef void (xxx)(); };
153
154<a href="./assert-not.html" class="identifier">BOOST_MPL_ASSERT_NOT</a>(( has_xxx&lt;test1&gt; ));
155<a href="./assert-not.html" class="identifier">BOOST_MPL_ASSERT_NOT</a>(( has_xxx&lt;test2&gt; ));
156<a href="./assert-not.html" class="identifier">BOOST_MPL_ASSERT_NOT</a>(( has_xxx&lt;test3&gt; ));
157<a href="./assert-not.html" class="identifier">BOOST_MPL_ASSERT_NOT</a>(( has_xxx&lt;test4&gt; ));
158<a href="./assert-not.html" class="identifier">BOOST_MPL_ASSERT_NOT</a>(( has_xxx&lt;test5&gt; ));
159
160#if !defined(<a href="./cfg-no-has-xxx.html" class="identifier">BOOST_MPL_CFG_NO_HAS_XXX</a>)
161<a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( has_xxx&lt;test6&gt; ));
162<a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( has_xxx&lt;test7&gt; ));
163<a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( has_xxx&lt;test8&gt; ));
164<a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( has_xxx&lt;test9&gt; ));
165#endif
166
167<a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( has_xxx&lt;test6,true_&gt; ));
168<a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( has_xxx&lt;test7,true_&gt; ));
169<a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( has_xxx&lt;test8,true_&gt; ));
170<a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( has_xxx&lt;test9,true_&gt; ));
171</pre>
172</div>
173<div class="section" id="macros-introspection-has-see-also">
174<h3><a class="subsection-title" href="#see-also" name="see-also">See also</a></h3>
175<p><a class="reference" href="./macros.html">Macros</a>, <a class="refentry reference" href="./has-xxx-trait-def.html"><tt class="refentry literal"><span class="pre">BOOST_MPL_HAS_XXX_TRAIT_DEF</span></tt></a>, <a class="refentry reference" href="./cfg-no-has-xxx.html"><tt class="refentry literal"><span class="pre">BOOST_MPL_CFG_NO_HAS_XXX</span></tt></a></p>
176<!-- modtime: November 13, 2004 02:53:15 +0000 -->
177</div>
178</div>
179
180<div class="footer-separator"></div>
181<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./has-xxx-trait-def.html" class="navigation-link">Prev</a>&nbsp;<a href="./configuration.html" class="navigation-link">Next</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./has-xxx-trait-def.html" class="navigation-link">Back</a>&nbsp;Along</span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./introspection.html" class="navigation-link">Up</a>&nbsp;<a href="../refmanual.html" class="navigation-link">Home</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./refmanual_toc.html" class="navigation-link">Full TOC</a></span></td>
182</tr></table></body>
183</html>
Note: See TracBrowser for help on using the repository browser.