2007-11-25 18:38:02 +00:00
< html >
< head >
< meta http-equiv = "Content-Type" content = "text/html; charset=ISO-8859-1" >
< title > Functional< / title >
< link rel = "stylesheet" href = "../../../../../doc/html/boostbook.css" type = "text/css" >
2008-07-08 02:43:21 +00:00
< meta name = "generator" content = "DocBook XSL Stylesheets V1.66.1" >
2007-11-25 18:38:02 +00:00
< link rel = "start" href = "../index.html" title = "Chapter<65> 1.<2E> Fusion 2.0" >
< link rel = "up" href = "../index.html" title = "Chapter<65> 1.<2E> Fusion 2.0" >
2007-12-21 03:13:31 +00:00
< link rel = "prev" href = "extension/iterator_facade.html" title = "Iterator Facade" >
2007-11-25 18:38:02 +00:00
< link rel = "next" href = "functional/concepts.html" title = "Concepts" >
< / head >
< body bgcolor = "white" text = "black" link = "#0000FF" vlink = "#840084" alink = "#0000FF" >
< table cellpadding = "2" width = "100%" > < tr >
< td valign = "top" > < img alt = "Boost C++ Libraries" width = "277" height = "86" src = "../../../../../boost.png" > < / td >
2008-07-17 23:59:40 +00:00
< td align = "center" > < a href = "../../../../../index.html" > Home< / a > < / td >
2007-11-25 18:38:02 +00:00
< td align = "center" > < a href = "../../../../libraries.htm" > Libraries< / a > < / td >
2008-07-17 23:59:40 +00:00
< td align = "center" > < a href = "http://www.boost.org/users/people.html" > People< / a > < / td >
< td align = "center" > < a href = "http://www.boost.org/users/faq.html" > FAQ< / a > < / td >
2007-11-25 18:38:02 +00:00
< td align = "center" > < a href = "../../../../../more/index.htm" > More< / a > < / td >
< / tr > < / table >
< hr >
< div class = "spirit-nav" >
2007-12-21 03:13:31 +00:00
< a accesskey = "p" href = "extension/iterator_facade.html" > < img src = "../../../../../doc/html/images/prev.png" alt = "Prev" > < / a > < a accesskey = "u" href = "../index.html" > < img src = "../../../../../doc/html/images/up.png" alt = "Up" > < / a > < a accesskey = "h" href = "../index.html" > < img src = "../../../../../doc/html/images/home.png" alt = "Home" > < / a > < a accesskey = "n" href = "functional/concepts.html" > < img src = "../../../../../doc/html/images/next.png" alt = "Next" > < / a >
2007-11-25 18:38:02 +00:00
< / div >
< div class = "section" lang = "en" >
< div class = "titlepage" > < div > < div > < h2 class = "title" style = "clear: both" >
2008-07-08 02:43:21 +00:00
< a name = "fusion.functional" > < / a > < a href = "functional.html" title = "Functional" > Functional< / a > < / h2 > < / div > < / div > < / div >
2007-11-25 18:38:02 +00:00
< div class = "toc" > < dl >
< dt > < span class = "section" > < a href = "functional/concepts.html" > Concepts< / a > < / span > < / dt >
< dd > < dl >
< dt > < span class = "section" > < a href = "functional/concepts/callable.html" > Callable Object< / a > < / span > < / dt >
< dt > < span class = "section" > < a href = "functional/concepts/reg_callable.html" > Regular Callable
Object< / a > < / span > < / dt >
< dt > < span class = "section" > < a href = "functional/concepts/def_callable.html" > Deferred
Callable Object< / a > < / span > < / dt >
< dt > < span class = "section" > < a href = "functional/concepts/poly.html" > Polymorphic Function
Object< / a > < / span > < / dt >
< / dl > < / dd >
< dt > < span class = "section" > < a href = "functional/invocation.html" > Invocation< / a > < / span > < / dt >
< dd > < dl >
< dt > < span class = "section" > < a href = "functional/invocation/functions.html" > Functions< / a > < / span > < / dt >
< dt > < span class = "section" > < a href = "functional/invocation/metafunctions.html" > Metafunctions< / a > < / span > < / dt >
< / dl > < / dd >
< dt > < span class = "section" > < a href = "functional/adapters.html" > Adapters< / a > < / span > < / dt >
< dd > < dl >
< dt > < span class = "section" > < a href = "functional/adapters/fused.html" > fused< / a > < / span > < / dt >
< dt > < span class = "section" > < a href = "functional/adapters/fused_procedure.html" > fused_procedure< / a > < / span > < / dt >
< dt > < span class = "section" > < a href = "functional/adapters/fused_function_object.html" > fused_function_object< / a > < / span > < / dt >
< dt > < span class = "section" > < a href = "functional/adapters/unfused_generic.html" > unfused_generic< / a > < / span > < / dt >
< dt > < span class = "section" > < a href = "functional/adapters/unfused_lvalue_args.html" > unfused_lvalue_args< / a > < / span > < / dt >
< dt > < span class = "section" > < a href = "functional/adapters/unfused_rvalue_args.html" > unfused_rvalue_args< / a > < / span > < / dt >
< dt > < span class = "section" > < a href = "functional/adapters/unfused_typed.html" > unfused_typed< / a > < / span > < / dt >
< / dl > < / dd >
< dt > < span class = "section" > < a href = "functional/generation.html" > Generation< / a > < / span > < / dt >
< dd > < dl >
< dt > < span class = "section" > < a href = "functional/generation/functions.html" > Functions< / a > < / span > < / dt >
< dt > < span class = "section" > < a href = "functional/generation/metafunctions.html" > Metafunctions< / a > < / span > < / dt >
< / dl > < / dd >
< / dl > < / div >
< p >
Components to call functions and function objects and to make Fusion code callable
through a function object interface.
< / p >
< p >
/functional.hpp>
< / p >
2008-07-08 02:43:21 +00:00
< a name = "fusion.functional.fused_and_unfused_forms" > < / a > < h3 >
2008-10-10 15:05:47 +00:00
< a name = "id653897" > < / a >
2008-07-08 02:43:21 +00:00
< a href = "functional.html#fusion.functional.fused_and_unfused_forms" > Fused and unfused
2007-11-25 18:38:02 +00:00
forms< / a >
2008-07-08 02:43:21 +00:00
< / h3 >
2007-11-25 18:38:02 +00:00
< p >
What is a function call?
< / p >
< 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 >
< / pre >
< p >
It is a name and a tuple written next to each other, left-to-right.
< / p >
< p >
2008-07-08 02:43:21 +00:00
Although the C++ syntax does not allow to replace < tt class = "literal" > (a,b,c)< / tt >
with some Fusion < a href = "sequence.html" title = "Sequence" > Sequence< / a > , introducing
2007-11-25 18:38:02 +00:00
yet another function provides a solution:
< / p >
< 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 >
< / pre >
< p >
2008-07-08 02:43:21 +00:00
Alternatively it is possible to apply a simple transformation to < tt class = "literal" > f< / tt >
2007-11-25 18:38:02 +00:00
in order to achieve the same effect:
< / p >
< pre class = "programlisting" >
< span class = "identifier" > f< / span > < span class = "identifier" > tuple< / span > < span class = "special" > < => < / span > f' < span class = "special" > (< / span > < span class = "identifier" > tuple< / span > < span class = "special" > )< / span >
< / pre >
< p >
2008-07-08 02:43:21 +00:00
Now, < tt class = "literal" > f'< / tt > is an unary function that takes the arguments to
< tt class = "computeroutput" > < span class = "identifier" > f< / span > < / tt > as a tuple; < tt class = "literal" > f'< / tt >
is the < span class = "emphasis" > < em > fused< / em > < / span > form of < tt class = "computeroutput" > < span class = "identifier" > f< / span > < / tt > .
2007-11-25 18:38:02 +00:00
Reading the above equivalence right-to-left to get the inverse transformation,
2008-07-08 02:43:21 +00:00
< tt class = "computeroutput" > < span class = "identifier" > f< / span > < / tt > is the < span class = "emphasis" > < em > unfused< / em > < / span >
form of < tt class = "literal" > f'< / tt > .
2007-11-25 18:38:02 +00:00
< / p >
2008-07-08 02:43:21 +00:00
< a name = "fusion.functional.calling_functions_and_function_objects" > < / a > < h3 >
2008-10-10 15:05:47 +00:00
< a name = "id654163" > < / a >
2008-07-08 02:43:21 +00:00
< a href = "functional.html#fusion.functional.calling_functions_and_function_objects" > Calling
2007-11-25 18:38:02 +00:00
functions and function objects< / a >
2008-07-08 02:43:21 +00:00
< / h3 >
2007-11-25 18:38:02 +00:00
< p >
Having generic C++ code call back arbitrary functions provided by the client
used to be a heavily repetitive task, as different functions can differ in
arity, invocation syntax and other properties that might be part of the type.
Transporting arguments as Fusion sequences and factoring out the invocation
makes Fusion algorithms applicable to function arguments and also reduces the
problem to one invocation syntax and a fixed arity (instead of an arbitrary
number of arbitrary arguments times several syntactic variants times additional
properties).
< / p >
< p >
Transforming an unfused function into its fused counterpart allows n-ary calls
2008-07-08 02:43:21 +00:00
from an algorithm that invokes an unary < a href = "functional/concepts/poly.html" title = " Polymorphic Function
Object">Polymorphic
Function Object< / a > with < a href = "sequence.html" title = "Sequence" > Sequence< / a >
2007-11-25 18:38:02 +00:00
arguments.
< / p >
< p >
The library provides several function templates to invoke different kinds of
functions and adapters to transform them into fused form, respectively. Every
variant has a corresponding generator function template that returns an adapter
instance for the given argument.
< / p >
2008-07-08 02:43:21 +00:00
< a name = "fusion.functional.making_fusion_code_callable_through_a_function_object_interface" > < / a > < h3 >
2008-10-10 15:05:47 +00:00
< a name = "id654239" > < / a >
2008-07-08 02:43:21 +00:00
< a href = "functional.html#fusion.functional.making_fusion_code_callable_through_a_function_object_interface" > Making
2007-11-25 18:38:02 +00:00
Fusion code callable through a function object interface< / a >
2008-07-08 02:43:21 +00:00
< / h3 >
2007-11-25 18:38:02 +00:00
< p >
Transforming a fused function into its unfused counterpart allows to create
function objects to accept arbitrary calls. In other words, an unary function
object can be implemented instead of (maybe heavily overloaded) function templates
or function call operators.
< / p >
< p >
The library provides several adapter variants that implement this transformation,
ranging from strictly typed to fully generic. The latter provides a reusable,
approximate solution to < a href = "http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2002/n1385.htm" target = "_top" > The
Forwarding Problem< / a > . Every generic variant has a corresponding generator
function template that returns an adapter instance for the given argument.
< / p >
< / div >
< table xmlns:rev = "http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width = "100%" > < tr >
< td align = "left" > < / td >
< td align = "right" > < div class = "copyright-footer" > Copyright <20> 2001-2007 Joel de Guzman, Dan Marsden, Tobias
Schwinger< p >
Distributed under the Boost Software License, Version 1.0. (See accompanying
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 > )
< / p >
< / div > < / td >
< / tr > < / table >
< hr >
< div class = "spirit-nav" >
2007-12-21 03:13:31 +00:00
< a accesskey = "p" href = "extension/iterator_facade.html" > < img src = "../../../../../doc/html/images/prev.png" alt = "Prev" > < / a > < a accesskey = "u" href = "../index.html" > < img src = "../../../../../doc/html/images/up.png" alt = "Up" > < / a > < a accesskey = "h" href = "../index.html" > < img src = "../../../../../doc/html/images/home.png" alt = "Home" > < / a > < a accesskey = "n" href = "functional/concepts.html" > < img src = "../../../../../doc/html/images/next.png" alt = "Next" > < / a >
2007-11-25 18:38:02 +00:00
< / div >
< / body >
< / html >