• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>BOOST_FUSION_DEFINE_ASSOC_STRUCT</title>
5<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../../index.html" title="Chapter 1. Fusion 2.2">
8<link rel="up" href="../adapted.html" title="Adapted">
9<link rel="prev" href="define_tpl_struct_inline.html" title="BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE">
10<link rel="next" href="define_assoc_tpl_struct.html" title="BOOST_FUSION_DEFINE_ASSOC_TPL_STRUCT">
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="define_tpl_struct_inline.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="define_assoc_tpl_struct.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.define_assoc_struct"></a><a class="link" href="define_assoc_struct.html" title="BOOST_FUSION_DEFINE_ASSOC_STRUCT">BOOST_FUSION_DEFINE_ASSOC_STRUCT</a>
28</h3></div></div></div>
29<h5>
30<a name="fusion.adapted.define_assoc_struct.h0"></a>
31        <span class="phrase"><a name="fusion.adapted.define_assoc_struct.description"></a></span><a class="link" href="define_assoc_struct.html#fusion.adapted.define_assoc_struct.description">Description</a>
32      </h5>
33<p>
34        BOOST_FUSION_DEFINE_ASSOC_STRUCT is a macro that can be used to generate
35        all the necessary boilerplate to define and adapt an arbitrary struct as
36        a model 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.define_assoc_struct.h1"></a>
42        <span class="phrase"><a name="fusion.adapted.define_assoc_struct.synopsis"></a></span><a class="link" href="define_assoc_struct.html#fusion.adapted.define_assoc_struct.synopsis">Synopsis</a>
43      </h5>
44<pre class="programlisting"><span class="identifier">BOOST_FUSION_DEFINE_ASSOC_STRUCT</span><span class="special">(</span>
45    <span class="special">(</span><span class="identifier">namespace0</span><span class="special">)(</span><span class="identifier">namespace1</span><span class="special">)...,</span>
46    <span class="identifier">struct_name</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<div class="variablelist">
53<p class="title"><b>Notation</b></p>
54<dl class="variablelist">
55<dt><span class="term"><code class="computeroutput"><span class="identifier">str</span></code></span></dt>
56<dd><p>
57              An instance of <code class="computeroutput"><span class="identifier">struct_name</span></code>
58            </p></dd>
59<dt><span class="term"><code class="computeroutput"><span class="identifier">e0</span></code>...<code class="computeroutput"><span class="identifier">en</span></code></span></dt>
60<dd><p>
61              Heterogeneous values
62            </p></dd>
63<dt><span class="term"><code class="computeroutput"><span class="identifier">fs</span></code></span></dt>
64<dd><p>
65              A <a class="link" href="../sequence/concepts/forward_sequence.html" title="Forward Sequence">Forward
66              Sequence</a>
67            </p></dd>
68</dl>
69</div>
70<h5>
71<a name="fusion.adapted.define_assoc_struct.h2"></a>
72        <span class="phrase"><a name="fusion.adapted.define_assoc_struct.expression_semantics"></a></span><a class="link" href="define_assoc_struct.html#fusion.adapted.define_assoc_struct.expression_semantics">Expression
73        Semantics</a>
74      </h5>
75<p>
76        The above macro generates the necessary code that defines and adapts <code class="computeroutput"><span class="identifier">struct_name</span></code> as a model of <a class="link" href="../sequence/concepts/random_access_sequence.html" title="Random Access Sequence">Random
77        Access Sequence</a> and <a class="link" href="../sequence/concepts/associative_sequence.html" title="Associative Sequence">Associative
78        Sequence</a>. The sequence <code class="computeroutput"><span class="special">(</span><span class="identifier">namespace0</span><span class="special">)(</span><span class="identifier">namespace1</span><span class="special">)...</span></code>
79        declares the namespace for <code class="computeroutput"><span class="identifier">struct_name</span></code>.
80        It yields to a fully qualified name for <code class="computeroutput"><span class="identifier">struct_name</span></code>
81        of <code class="computeroutput"><span class="identifier">namespace0</span><span class="special">::</span><span class="identifier">namespace1</span><span class="special">::...</span>
82        <span class="identifier">struct_name</span></code>. If an empty namespace
83        sequence is given (that is a macro that expands to nothing), the struct is
84        placed in the global namespace. The sequence of <code class="computeroutput"><span class="special">(</span><span class="identifier">member_typeN</span><span class="special">,</span>
85        <span class="identifier">member_nameN</span><span class="special">,</span>
86        <span class="identifier">key_typeN</span><span class="special">)</span></code>
87        triples declares the type, name and key type of each of the struct members
88        that are part of the sequence.
89      </p>
90<p>
91        The macro should be used at global scope. Semantics of an expression is defined
92        only where it differs from, or is not defined in <a class="link" href="../sequence/concepts/random_access_sequence.html" title="Random Access Sequence">Random
93        Access Sequence</a> and <a class="link" href="../sequence/concepts/associative_sequence.html" title="Associative Sequence">Associative
94        Sequence</a>.
95      </p>
96<div class="informaltable"><table class="table">
97<colgroup>
98<col>
99<col>
100</colgroup>
101<thead><tr>
102<th>
103                <p>
104                  Expression
105                </p>
106              </th>
107<th>
108                <p>
109                  Semantics
110                </p>
111              </th>
112</tr></thead>
113<tbody>
114<tr>
115<td>
116                <p>
117                  <code class="computeroutput"><span class="identifier">struct_name</span><span class="special">()</span></code>
118                </p>
119              </td>
120<td>
121                <p>
122                  Creates an instance of <code class="computeroutput"><span class="identifier">struct_name</span></code>
123                  with default constructed elements.
124                </p>
125              </td>
126</tr>
127<tr>
128<td>
129                <p>
130                  <code class="computeroutput"><span class="identifier">struct_name</span><span class="special">(</span><span class="identifier">e0</span><span class="special">,</span>
131                  <span class="identifier">e1</span><span class="special">,...</span>
132                  <span class="identifier">en</span><span class="special">)</span></code>
133                </p>
134              </td>
135<td>
136                <p>
137                  Creates an instance of <code class="computeroutput"><span class="identifier">struct_name</span></code>
138                  with elements <code class="computeroutput"><span class="identifier">e0</span></code>...<code class="computeroutput"><span class="identifier">en</span></code>.
139                </p>
140              </td>
141</tr>
142<tr>
143<td>
144                <p>
145                  <code class="computeroutput"><span class="identifier">struct_name</span><span class="special">(</span><span class="identifier">fs</span><span class="special">)</span></code>
146                </p>
147              </td>
148<td>
149                <p>
150                  Copy constructs an instance of <code class="computeroutput"><span class="identifier">struct_name</span></code>
151                  from a <a class="link" href="../sequence/concepts/forward_sequence.html" title="Forward Sequence">Forward
152                  Sequence</a> <code class="computeroutput"><span class="identifier">fs</span></code>.
153                </p>
154              </td>
155</tr>
156<tr>
157<td>
158                <p>
159                  <code class="computeroutput"><span class="identifier">str</span> <span class="special">=</span>
160                  <span class="identifier">fs</span></code>
161                </p>
162              </td>
163<td>
164                <p>
165                  Assigns from a <a class="link" href="../sequence/concepts/forward_sequence.html" title="Forward Sequence">Forward
166                  Sequence</a> <code class="computeroutput"><span class="identifier">fs</span></code>.
167                </p>
168              </td>
169</tr>
170<tr>
171<td>
172                <p>
173                  <code class="computeroutput"><span class="identifier">str</span><span class="special">.</span><span class="identifier">member_nameN</span></code>
174                </p>
175              </td>
176<td>
177                <p>
178                  Access of struct member <code class="computeroutput"><span class="identifier">member_nameN</span></code>
179                </p>
180              </td>
181</tr>
182</tbody>
183</table></div>
184<h5>
185<a name="fusion.adapted.define_assoc_struct.h3"></a>
186        <span class="phrase"><a name="fusion.adapted.define_assoc_struct.header"></a></span><a class="link" href="define_assoc_struct.html#fusion.adapted.define_assoc_struct.header">Header</a>
187      </h5>
188<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">define_assoc_struct</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
189<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">define_assoc_struct</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
190</pre>
191<h5>
192<a name="fusion.adapted.define_assoc_struct.h4"></a>
193        <span class="phrase"><a name="fusion.adapted.define_assoc_struct.example"></a></span><a class="link" href="define_assoc_struct.html#fusion.adapted.define_assoc_struct.example">Example</a>
194      </h5>
195<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">keys</span>
196<span class="special">{</span>
197    <span class="keyword">struct</span> <span class="identifier">name</span><span class="special">;</span>
198    <span class="keyword">struct</span> <span class="identifier">age</span><span class="special">;</span>
199<span class="special">}</span>
200
201<span class="comment">// demo::employee is a Fusion sequence</span>
202<span class="identifier">BOOST_FUSION_DEFINE_ASSOC_STRUCT</span><span class="special">(</span>
203    <span class="special">(</span><span class="identifier">demo</span><span class="special">),</span> <span class="identifier">employee</span><span class="special">,</span>
204    <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</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>
205    <span class="special">(</span><span class="keyword">int</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>
206</pre>
207</div>
208<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
209<td align="left"></td>
210<td align="right"><div class="copyright-footer">Copyright © 2001-2006, 2011, 2012 Joel de Guzman,
211      Dan Marsden, Tobias Schwinger<p>
212        Distributed under the Boost Software License, Version 1.0. (See accompanying
213        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>)
214      </p>
215</div></td>
216</tr></table>
217<hr>
218<div class="spirit-nav">
219<a accesskey="p" href="define_tpl_struct_inline.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="define_assoc_tpl_struct.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
220</div>
221</body>
222</html>
223