571df70c9f1ac7262f644cbb6e9f0f0ebe4f780d
[platform/upstream/boost.git] / libs / fusion / doc / html / fusion / adapted / adapt_assoc_tpl_struct.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT</title>
5 <link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
7 <link rel="home" href="../../index.html" title="Chapter&#160;1.&#160;Fusion 2.2">
8 <link rel="up" href="../adapted.html" title="Adapted">
9 <link rel="prev" href="adapt_assoc.html" title="BOOST_FUSION_ADAPT_ASSOC_STRUCT">
10 <link rel="next" href="adapt_assoc_struct_named.html" title="BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED">
11 </head>
12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13 <table cellpadding="2" width="100%"><tr>
14 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
15 <td align="center"><a href="../../../../../../index.html">Home</a></td>
16 <td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
17 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19 <td align="center"><a href="../../../../../../more/index.htm">More</a></td>
20 </tr></table>
21 <hr>
22 <div class="spirit-nav">
23 <a accesskey="p" href="adapt_assoc.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../adapted.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="adapt_assoc_struct_named.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
24 </div>
25 <div class="section">
26 <div class="titlepage"><div><div><h3 class="title">
27 <a name="fusion.adapted.adapt_assoc_tpl_struct"></a><a class="link" href="adapt_assoc_tpl_struct.html" title="BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT">BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT</a>
28 </h3></div></div></div>
29 <h5>
30 <a name="fusion.adapted.adapt_assoc_tpl_struct.h0"></a>
31         <span class="phrase"><a name="fusion.adapted.adapt_assoc_tpl_struct.description"></a></span><a class="link" href="adapt_assoc_tpl_struct.html#fusion.adapted.adapt_assoc_tpl_struct.description">Description</a>
32       </h5>
33 <p>
34         BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT is a macro that can be used to generate
35         all the necessary boilerplate to make an arbitrary template struct a model
36         of <a class="link" href="../sequence/concepts/random_access_sequence.html" title="Random Access Sequence">Random
37         Access Sequence</a> and <a class="link" href="../sequence/concepts/associative_sequence.html" title="Associative Sequence">Associative
38         Sequence</a>.
39       </p>
40 <h5>
41 <a name="fusion.adapted.adapt_assoc_tpl_struct.h1"></a>
42         <span class="phrase"><a name="fusion.adapted.adapt_assoc_tpl_struct.synopsis"></a></span><a class="link" href="adapt_assoc_tpl_struct.html#fusion.adapted.adapt_assoc_tpl_struct.synopsis">Synopsis</a>
43       </h5>
44 <pre class="programlisting"><span class="identifier">BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT</span><span class="special">(</span>
45     <span class="special">(</span><span class="identifier">template_param0</span><span class="special">)(</span><span class="identifier">template_param1</span><span class="special">)...,</span>
46     <span class="special">(</span><span class="identifier">struct_name</span><span class="special">)</span> <span class="special">(</span><span class="identifier">specialization_param0</span><span class="special">)(</span><span class="identifier">specialization_param1</span><span class="special">)...,</span>
47     <span class="special">(</span><span class="identifier">member_type0</span><span class="special">,</span> <span class="identifier">member_name0</span><span class="special">,</span> <span class="identifier">key_type0</span><span class="special">)</span>
48     <span class="special">(</span><span class="identifier">member_type1</span><span class="special">,</span> <span class="identifier">member_name1</span><span class="special">,</span> <span class="identifier">key_type1</span><span class="special">)</span>
49     <span class="special">...</span>
50     <span class="special">)</span>
51 </pre>
52 <h5>
53 <a name="fusion.adapted.adapt_assoc_tpl_struct.h2"></a>
54         <span class="phrase"><a name="fusion.adapted.adapt_assoc_tpl_struct.semantics"></a></span><a class="link" href="adapt_assoc_tpl_struct.html#fusion.adapted.adapt_assoc_tpl_struct.semantics">Semantics</a>
55       </h5>
56 <p>
57         The above macro generates the necessary code to adapt <code class="computeroutput"><span class="identifier">struct_name</span></code>
58         or an arbitrary specialization of <code class="computeroutput"><span class="identifier">struct_name</span></code>
59         as a model of <a class="link" href="../sequence/concepts/random_access_sequence.html" title="Random Access Sequence">Random
60         Access Sequence</a> and <a class="link" href="../sequence/concepts/associative_sequence.html" title="Associative Sequence">Associative
61         Sequence</a>. The sequence <code class="computeroutput"><span class="special">(</span><span class="identifier">template_param0</span><span class="special">)(</span><span class="identifier">template_param1</span><span class="special">)...</span></code>
62         declares the names of the template type parameters used. The sequence <code class="computeroutput"><span class="special">(</span><span class="identifier">specialization_param0</span><span class="special">)(</span><span class="identifier">specialization_param1</span><span class="special">)...</span></code> declares the template parameters of the
63         actual specialization of <code class="computeroutput"><span class="identifier">struct_name</span></code>
64         that is adapted as a fusion sequence. The sequence of <code class="computeroutput"><span class="special">(</span><span class="identifier">member_typeN</span><span class="special">,</span>
65         <span class="identifier">member_nameN</span><span class="special">,</span>
66         <span class="identifier">key_typeN</span><span class="special">)</span></code>
67         triples declares the type, name and key type of each of the struct members
68         that are part of the sequence.
69       </p>
70 <p>
71         The macro should be used at global scope, and <code class="computeroutput"><span class="identifier">struct_name</span></code>
72         should be the fully namespace qualified name of the struct to be adapted.
73       </p>
74 <h5>
75 <a name="fusion.adapted.adapt_assoc_tpl_struct.h3"></a>
76         <span class="phrase"><a name="fusion.adapted.adapt_assoc_tpl_struct.header"></a></span><a class="link" href="adapt_assoc_tpl_struct.html#fusion.adapted.adapt_assoc_tpl_struct.header">Header</a>
77       </h5>
78 <pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">fusion</span><span class="special">/</span><span class="identifier">adapted</span><span class="special">/</span><span class="keyword">struct</span><span class="special">/</span><span class="identifier">adapt_assoc_struct</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
79 <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">fusion</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">adapt_assoc_struct</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
80 </pre>
81 <h5>
82 <a name="fusion.adapted.adapt_assoc_tpl_struct.h4"></a>
83         <span class="phrase"><a name="fusion.adapted.adapt_assoc_tpl_struct.example"></a></span><a class="link" href="adapt_assoc_tpl_struct.html#fusion.adapted.adapt_assoc_tpl_struct.example">Example</a>
84       </h5>
85 <pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">demo</span>
86 <span class="special">{</span>
87     <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Name</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Age</span><span class="special">&gt;</span>
88     <span class="keyword">struct</span> <span class="identifier">employee</span>
89     <span class="special">{</span>
90         <span class="identifier">Name</span> <span class="identifier">name</span><span class="special">;</span>
91         <span class="identifier">Age</span> <span class="identifier">age</span><span class="special">;</span>
92     <span class="special">};</span>
93 <span class="special">}</span>
94
95 <span class="keyword">namespace</span> <span class="identifier">keys</span>
96 <span class="special">{</span>
97     <span class="keyword">struct</span> <span class="identifier">name</span><span class="special">;</span>
98     <span class="keyword">struct</span> <span class="identifier">age</span><span class="special">;</span>
99 <span class="special">}</span>
100
101 <span class="comment">// Any instantiated demo::employee is now a Fusion sequence.</span>
102 <span class="comment">// It is also an associative sequence with</span>
103 <span class="comment">// keys keys::name and keys::age present.</span>
104 <span class="identifier">BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT</span><span class="special">(</span>
105     <span class="special">(</span><span class="identifier">Name</span><span class="special">)(</span><span class="identifier">Age</span><span class="special">),</span>
106     <span class="special">(</span><span class="identifier">demo</span><span class="special">::</span><span class="identifier">employee</span><span class="special">)</span> <span class="special">(</span><span class="identifier">Name</span><span class="special">)(</span><span class="identifier">Age</span><span class="special">),</span>
107     <span class="special">(</span><span class="identifier">Name</span><span class="special">,</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">keys</span><span class="special">::</span><span class="identifier">name</span><span class="special">)</span>
108     <span class="special">(</span><span class="identifier">Age</span><span class="special">,</span> <span class="identifier">age</span><span class="special">,</span> <span class="identifier">keys</span><span class="special">::</span><span class="identifier">age</span><span class="special">))</span>
109 </pre>
110 </div>
111 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
112 <td align="left"></td>
113 <td align="right"><div class="copyright-footer">Copyright &#169; 2001-2006, 2011, 2012 Joel de Guzman,
114       Dan Marsden, Tobias Schwinger<p>
115         Distributed under the Boost Software License, Version 1.0. (See accompanying
116         file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
117       </p>
118 </div></td>
119 </tr></table>
120 <hr>
121 <div class="spirit-nav">
122 <a accesskey="p" href="adapt_assoc.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../adapted.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="adapt_assoc_struct_named.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
123 </div>
124 </body>
125 </html>