• 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_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.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="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        tuples 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        When member_typeN is omitted or set to auto, the type is infered with Boost.TypeOf.
72      </p>
73<p>
74        The macro should be used at global scope, and <code class="computeroutput"><span class="identifier">struct_name</span></code>
75        should be the fully namespace qualified name of the struct to be adapted.
76      </p>
77<h5>
78<a name="fusion.adapted.adapt_assoc_tpl_struct.h3"></a>
79        <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>
80      </h5>
81<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>
82<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>
83</pre>
84<h5>
85<a name="fusion.adapted.adapt_assoc_tpl_struct.h4"></a>
86        <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>
87      </h5>
88<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">demo</span>
89<span class="special">{</span>
90    <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>
91    <span class="keyword">struct</span> <span class="identifier">employee</span>
92    <span class="special">{</span>
93        <span class="identifier">Name</span> <span class="identifier">name</span><span class="special">;</span>
94        <span class="identifier">Age</span> <span class="identifier">age</span><span class="special">;</span>
95    <span class="special">};</span>
96<span class="special">}</span>
97
98<span class="keyword">namespace</span> <span class="identifier">keys</span>
99<span class="special">{</span>
100    <span class="keyword">struct</span> <span class="identifier">name</span><span class="special">;</span>
101    <span class="keyword">struct</span> <span class="identifier">age</span><span class="special">;</span>
102<span class="special">}</span>
103
104<span class="comment">// Any instantiated demo::employee is now a Fusion sequence.</span>
105<span class="comment">// It is also an associative sequence with</span>
106<span class="comment">// keys keys::name and keys::age present.</span>
107<span class="identifier">BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT</span><span class="special">(</span>
108    <span class="special">(</span><span class="identifier">Name</span><span class="special">)(</span><span class="identifier">Age</span><span class="special">),</span>
109    <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>
110    <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>
111    <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>
112
113<span class="comment">// Without BOOST_PP_VARIADICS support :</span>
114<span class="identifier">BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT</span><span class="special">(</span>
115    <span class="special">(</span><span class="identifier">Name</span><span class="special">)(</span><span class="identifier">Age</span><span class="special">),</span>
116    <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>
117    <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>
118    <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>
119</pre>
120</div>
121<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
122<td align="left"></td>
123<td align="right"><div class="copyright-footer">Copyright © 2001-2006, 2011, 2012 Joel de Guzman,
124      Dan Marsden, Tobias Schwinger<p>
125        Distributed under the Boost Software License, Version 1.0. (See accompanying
126        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>)
127      </p>
128</div></td>
129</tr></table>
130<hr>
131<div class="spirit-nav">
132<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>
133</div>
134</body>
135</html>
136