36592bc8270049cd15245433a1e2dc79904d80ab
[platform/upstream/boost.git] / libs / fusion / doc / html / fusion / functional.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Functional</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="../index.html" title="Chapter&#160;1.&#160;Fusion 2.2">
9 <link rel="prev" href="extension/iterator_facade.html" title="Iterator Facade">
10 <link rel="next" href="functional/concepts.html" title="Concepts">
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="extension/iterator_facade.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.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="functional/concepts.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
24 </div>
25 <div class="section">
26 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
27 <a name="fusion.functional"></a><a class="link" href="functional.html" title="Functional">Functional</a>
28 </h2></div></div></div>
29 <div class="toc"><dl class="toc">
30 <dt><span class="section"><a href="functional/concepts.html">Concepts</a></span></dt>
31 <dd><dl>
32 <dt><span class="section"><a href="functional/concepts/callable.html">Callable Object</a></span></dt>
33 <dt><span class="section"><a href="functional/concepts/reg_callable.html">Regular Callable
34         Object</a></span></dt>
35 <dt><span class="section"><a href="functional/concepts/def_callable.html">Deferred Callable
36         Object</a></span></dt>
37 <dt><span class="section"><a href="functional/concepts/poly.html">Polymorphic Function
38         Object</a></span></dt>
39 </dl></dd>
40 <dt><span class="section"><a href="functional/invocation.html">Invocation</a></span></dt>
41 <dd><dl>
42 <dt><span class="section"><a href="functional/invocation/functions.html">Functions</a></span></dt>
43 <dt><span class="section"><a href="functional/invocation/metafunctions.html">Metafunctions</a></span></dt>
44 <dt><span class="section"><a href="functional/invocation/limits.html">Limits</a></span></dt>
45 </dl></dd>
46 <dt><span class="section"><a href="functional/adapters.html">Adapters</a></span></dt>
47 <dd><dl>
48 <dt><span class="section"><a href="functional/adapters/fused.html">fused</a></span></dt>
49 <dt><span class="section"><a href="functional/adapters/fused_procedure.html">fused_procedure</a></span></dt>
50 <dt><span class="section"><a href="functional/adapters/fused_function_object.html">fused_function_object</a></span></dt>
51 <dt><span class="section"><a href="functional/adapters/unfused.html">unfused</a></span></dt>
52 <dt><span class="section"><a href="functional/adapters/unfused_typed.html">unfused_typed</a></span></dt>
53 <dt><span class="section"><a href="functional/adapters/limits.html">Limits</a></span></dt>
54 </dl></dd>
55 <dt><span class="section"><a href="functional/generation.html">Generation</a></span></dt>
56 <dd><dl>
57 <dt><span class="section"><a href="functional/generation/functions.html">Functions</a></span></dt>
58 <dt><span class="section"><a href="functional/generation/metafunctions.html">Metafunctions</a></span></dt>
59 </dl></dd>
60 </dl></div>
61 <p>
62       Components to call functions and function objects and to make Fusion code callable
63       through a function object interface.
64     </p>
65 <h4>
66 <a name="fusion.functional.h0"></a>
67       <span class="phrase"><a name="fusion.functional.header"></a></span><a class="link" href="functional.html#fusion.functional.header">Header</a>
68     </h4>
69 <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">functional</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
70 </pre>
71 <h4>
72 <a name="fusion.functional.h1"></a>
73       <span class="phrase"><a name="fusion.functional.fused_and_unfused_forms"></a></span><a class="link" href="functional.html#fusion.functional.fused_and_unfused_forms">Fused
74       and unfused forms</a>
75     </h4>
76 <p>
77       What is a function call?
78     </p>
79 <pre class="programlisting"><span class="identifier">f</span> <span class="special">(</span><span class="identifier">a</span><span class="special">,</span><span class="identifier">b</span><span class="special">,</span><span class="identifier">c</span><span class="special">)</span>
80 </pre>
81 <p>
82       It is a name and a tuple written next to each other, left-to-right.
83     </p>
84 <p>
85       Although the C++ syntax does not allow to replace <code class="literal">(a,b,c)</code>
86       with some Fusion <a class="link" href="sequence.html" title="Sequence">Sequence</a>, introducing
87       yet another function provides a solution:
88     </p>
89 <pre class="programlisting"><span class="identifier">invoke</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span><span class="identifier">my_sequence</span><span class="special">)</span>
90 </pre>
91 <p>
92       Alternatively it is possible to apply a simple transformation to <code class="literal">f</code>
93       in order to achieve the same effect:
94     </p>
95 <pre class="programlisting"><span class="identifier">f</span> <span class="identifier">tuple</span> <span class="special">&lt;=&gt;</span> f' <span class="special">(</span><span class="identifier">tuple</span><span class="special">)</span>
96 </pre>
97 <p>
98       Now, <code class="literal">f'</code> is an unary function that takes the arguments to
99       <code class="computeroutput"><span class="identifier">f</span></code> as a tuple; <code class="literal">f'</code>
100       is the <span class="emphasis"><em>fused</em></span> form of <code class="computeroutput"><span class="identifier">f</span></code>.
101       Reading the above equivalence right-to-left to get the inverse transformation,
102       <code class="computeroutput"><span class="identifier">f</span></code> is the <span class="emphasis"><em>unfused</em></span>
103       form of <code class="literal">f'</code>.
104     </p>
105 <h4>
106 <a name="fusion.functional.h2"></a>
107       <span class="phrase"><a name="fusion.functional.calling_functions_and_function_objects"></a></span><a class="link" href="functional.html#fusion.functional.calling_functions_and_function_objects">Calling
108       functions and function objects</a>
109     </h4>
110 <p>
111       Having generic C++ code call back arbitrary functions provided by the client
112       used to be a heavily repetitive task, as different functions can differ in
113       arity, invocation syntax and other properties that might be part of the type.
114       Transporting arguments as Fusion sequences and factoring out the invocation
115       makes Fusion algorithms applicable to function arguments and also reduces the
116       problem to one invocation syntax and a fixed arity (instead of an arbitrary
117       number of arbitrary arguments times several syntactic variants times additional
118       properties).
119     </p>
120 <p>
121       Transforming an unfused function into its fused counterpart allows n-ary calls
122       from an algorithm that invokes an unary <a class="link" href="functional/concepts/poly.html" title="Polymorphic Function Object">Polymorphic
123       Function Object</a> with <a class="link" href="sequence.html" title="Sequence">Sequence</a>
124       arguments.
125     </p>
126 <p>
127       The library provides several function templates to invoke different kinds of
128       functions and adapters to transform them into fused form, respectively. Every
129       variant has a corresponding generator function template that returns an adapter
130       instance for the given argument.
131     </p>
132 <p>
133       Constructors can be called applying <a href="http://www.boost.org/libs/functional/factory/doc/html/index.html" target="_top">Boost.Functional/Factory</a>.
134     </p>
135 <h4>
136 <a name="fusion.functional.h3"></a>
137       <span class="phrase"><a name="fusion.functional.making_fusion_code_callable_through_a_function_object_interface"></a></span><a class="link" href="functional.html#fusion.functional.making_fusion_code_callable_through_a_function_object_interface">Making
138       Fusion code callable through a function object interface</a>
139     </h4>
140 <p>
141       Transforming a fused function into its unfused counterpart allows to create
142       function objects to accept arbitrary calls. In other words, an unary function
143       object can be implemented instead of (maybe heavily overloaded) function templates
144       or function call operators.
145     </p>
146 <p>
147       The library provides both a strictly typed and a generic variant for this transformation.
148       The latter should be used in combination with <a href="http://www.boost.org/libs/functional/forward/doc/html/index.html" target="_top">Boost.Functional/Forward</a>
149       to attack <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2002/n1385.htm" target="_top">The
150       Forwarding Problem</a>.
151     </p>
152 <p>
153       Both variants have a corresponding generator function template that returns
154       an adapter instance for the given argument.
155     </p>
156 </div>
157 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
158 <td align="left"></td>
159 <td align="right"><div class="copyright-footer">Copyright &#169; 2001-2006, 2011, 2012 Joel de Guzman,
160       Dan Marsden, Tobias Schwinger<p>
161         Distributed under the Boost Software License, Version 1.0. (See accompanying
162         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>)
163       </p>
164 </div></td>
165 </tr></table>
166 <hr>
167 <div class="spirit-nav">
168 <a accesskey="p" href="extension/iterator_facade.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.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="functional/concepts.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
169 </div>
170 </body>
171 </html>