• 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_TPL_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_struct.html" title="BOOST_FUSION_DEFINE_STRUCT">
10<link rel="next" href="define_struct_inline.html" title="BOOST_FUSION_DEFINE_STRUCT_INLINE">
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_struct.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_struct_inline.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_tpl_struct"></a><a class="link" href="define_tpl_struct.html" title="BOOST_FUSION_DEFINE_TPL_STRUCT">BOOST_FUSION_DEFINE_TPL_STRUCT</a>
28</h3></div></div></div>
29<h5>
30<a name="fusion.adapted.define_tpl_struct.h0"></a>
31        <span class="phrase"><a name="fusion.adapted.define_tpl_struct.description"></a></span><a class="link" href="define_tpl_struct.html#fusion.adapted.define_tpl_struct.description">Description</a>
32      </h5>
33<p>
34        BOOST_FUSION_DEFINE_TPL_STRUCT is a macro that can be used to generate all
35        the necessary boilerplate to define and adapt an arbitrary template struct
36        as a model of <a class="link" href="../sequence/concepts/random_access_sequence.html" title="Random Access Sequence">Random
37        Access Sequence</a>.
38      </p>
39<h5>
40<a name="fusion.adapted.define_tpl_struct.h1"></a>
41        <span class="phrase"><a name="fusion.adapted.define_tpl_struct.synopsis"></a></span><a class="link" href="define_tpl_struct.html#fusion.adapted.define_tpl_struct.synopsis">Synopsis</a>
42      </h5>
43<pre class="programlisting"><span class="identifier">BOOST_FUSION_DEFINE_TPL_STRUCT</span><span class="special">(</span>
44    <span class="special">(</span><span class="identifier">template_param0</span><span class="special">)(</span><span class="identifier">template_param1</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>
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>
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 instantiated <code class="computeroutput"><span class="identifier">struct_name</span></code>
58            </p></dd>
59<dt><span class="term"><code class="computeroutput"><span class="identifier">str</span></code></span></dt>
60<dd><p>
61              An instance of <code class="computeroutput"><span class="identifier">Str</span></code>
62            </p></dd>
63<dt><span class="term"><code class="computeroutput"><span class="identifier">e0</span></code>...<code class="computeroutput"><span class="identifier">en</span></code></span></dt>
64<dd><p>
65              Heterogeneous values
66            </p></dd>
67<dt><span class="term"><code class="computeroutput"><span class="identifier">fs</span></code></span></dt>
68<dd><p>
69              A <a class="link" href="../sequence/concepts/forward_sequence.html" title="Forward Sequence">Forward
70              Sequence</a>
71            </p></dd>
72</dl>
73</div>
74<h5>
75<a name="fusion.adapted.define_tpl_struct.h2"></a>
76        <span class="phrase"><a name="fusion.adapted.define_tpl_struct.expression_semantics"></a></span><a class="link" href="define_tpl_struct.html#fusion.adapted.define_tpl_struct.expression_semantics">Expression
77        Semantics</a>
78      </h5>
79<p>
80        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
81        Access 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>
82        declares the names of the template type parameters used. 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> declares the namespace for <code class="computeroutput"><span class="identifier">struct_name</span></code>. It yields to a fully qualified
83        name for <code class="computeroutput"><span class="identifier">struct_name</span></code> of
84        <code class="computeroutput"><span class="identifier">namespace0</span><span class="special">::</span><span class="identifier">namespace1</span><span class="special">::...</span>
85        <span class="identifier">struct_name</span></code>. If an empty namespace
86        sequence is given (that is a macro that expands to nothing), the struct is
87        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>
88        <span class="identifier">member_nameN</span><span class="special">)</span></code>
89        pairs declares the type and names of each of the struct members that are
90        part of the sequence.
91      </p>
92<p>
93        The macro should be used at global scope. Semantics of an expression is defined
94        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
95        Access Sequence</a>.
96      </p>
97<div class="informaltable"><table class="table">
98<colgroup>
99<col>
100<col>
101</colgroup>
102<thead><tr>
103<th>
104                <p>
105                  Expression
106                </p>
107              </th>
108<th>
109                <p>
110                  Semantics
111                </p>
112              </th>
113</tr></thead>
114<tbody>
115<tr>
116<td>
117                <p>
118                  <code class="computeroutput"><span class="identifier">Str</span><span class="special">()</span></code>
119                </p>
120              </td>
121<td>
122                <p>
123                  Creates an instance of <code class="computeroutput"><span class="identifier">Str</span></code>
124                  with default constructed elements.
125                </p>
126              </td>
127</tr>
128<tr>
129<td>
130                <p>
131                  <code class="computeroutput"><span class="identifier">Str</span><span class="special">(</span><span class="identifier">e0</span><span class="special">,</span>
132                  <span class="identifier">e1</span><span class="special">,...</span>
133                  <span class="identifier">en</span><span class="special">)</span></code>
134                </p>
135              </td>
136<td>
137                <p>
138                  Creates an instance of <code class="computeroutput"><span class="identifier">Str</span></code>
139                  with elements <code class="computeroutput"><span class="identifier">e0</span></code>...<code class="computeroutput"><span class="identifier">en</span></code>.
140                </p>
141              </td>
142</tr>
143<tr>
144<td>
145                <p>
146                  <code class="computeroutput"><span class="identifier">Str</span><span class="special">(</span><span class="identifier">fs</span><span class="special">)</span></code>
147                </p>
148              </td>
149<td>
150                <p>
151                  Copy constructs an instance of <code class="computeroutput"><span class="identifier">Str</span></code>
152                  from a <a class="link" href="../sequence/concepts/forward_sequence.html" title="Forward Sequence">Forward
153                  Sequence</a> <code class="computeroutput"><span class="identifier">fs</span></code>.
154                </p>
155              </td>
156</tr>
157<tr>
158<td>
159                <p>
160                  <code class="computeroutput"><span class="identifier">str</span> <span class="special">=</span>
161                  <span class="identifier">fs</span></code>
162                </p>
163              </td>
164<td>
165                <p>
166                  Assigns from a <a class="link" href="../sequence/concepts/forward_sequence.html" title="Forward Sequence">Forward
167                  Sequence</a> <code class="computeroutput"><span class="identifier">fs</span></code>.
168                </p>
169              </td>
170</tr>
171<tr>
172<td>
173                <p>
174                  <code class="computeroutput"><span class="identifier">str</span><span class="special">.</span><span class="identifier">member_nameN</span></code>
175                </p>
176              </td>
177<td>
178                <p>
179                  Access of struct member <code class="computeroutput"><span class="identifier">member_nameN</span></code>
180                </p>
181              </td>
182</tr>
183</tbody>
184</table></div>
185<h5>
186<a name="fusion.adapted.define_tpl_struct.h3"></a>
187        <span class="phrase"><a name="fusion.adapted.define_tpl_struct.header"></a></span><a class="link" href="define_tpl_struct.html#fusion.adapted.define_tpl_struct.header">Header</a>
188      </h5>
189<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_struct</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
190<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_struct</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
191</pre>
192<h5>
193<a name="fusion.adapted.define_tpl_struct.h4"></a>
194        <span class="phrase"><a name="fusion.adapted.define_tpl_struct.example"></a></span><a class="link" href="define_tpl_struct.html#fusion.adapted.define_tpl_struct.example">Example</a>
195      </h5>
196<pre class="programlisting"><span class="comment">// Any instantiated demo::employee is a Fusion sequence</span>
197<span class="identifier">BOOST_FUSION_DEFINE_TPL_STRUCT</span><span class="special">(</span>
198    <span class="special">(</span><span class="identifier">Name</span><span class="special">)(</span><span class="identifier">Age</span><span class="special">),</span> <span class="special">(</span><span class="identifier">demo</span><span class="special">),</span> <span class="identifier">employee</span><span class="special">,</span>
199    <span class="special">(</span><span class="identifier">Name</span><span class="special">,</span> <span class="identifier">name</span><span class="special">)</span>
200    <span class="special">(</span><span class="identifier">Age</span><span class="special">,</span> <span class="identifier">age</span><span class="special">))</span>
201</pre>
202</div>
203<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
204<td align="left"></td>
205<td align="right"><div class="copyright-footer">Copyright © 2001-2006, 2011, 2012 Joel de Guzman,
206      Dan Marsden, Tobias Schwinger<p>
207        Distributed under the Boost Software License, Version 1.0. (See accompanying
208        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>)
209      </p>
210</div></td>
211</tr></table>
212<hr>
213<div class="spirit-nav">
214<a accesskey="p" href="define_struct.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_struct_inline.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
215</div>
216</body>
217</html>
218