2007-11-06 12:13:52 +00:00
< html >
< head >
2009-12-11 21:01:22 +00:00
< meta http-equiv = "Content-Type" content = "text/html; charset=US-ASCII" >
2007-11-06 12:13:52 +00:00
< title > Algorithm</ title >
2007-11-07 03:46:23 +00:00
< link rel = "stylesheet" href = "../../../../../doc/html/boostbook.css" type = "text/css" >
2009-10-24 10:59:01 +00:00
< meta name = "generator" content = "DocBook XSL Stylesheets V1.75.1" >
2009-12-11 21:01:22 +00:00
< link rel = "home" href = "../index.html" title = "Chapter 1. Fusion 2.0" >
< link rel = "up" href = "../index.html" title = "Chapter 1. Fusion 2.0" >
2009-09-25 00:21:53 +00:00
< link rel = "prev" href = "adapted/adapt_assoc.html" title = "BOOST_FUSION_ADAPT_ASSOC_STRUCT" >
2007-11-06 12:13:52 +00:00
< link rel = "next" href = "algorithm/iteration.html" title = "Iteration" >
</ 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:22 +00:00
< td align = "center" >< a href = "../../../../../index.html" > Home</ a ></ td >
2007-11-06 12:13:52 +00:00
< td align = "center" >< a href = "../../../../libraries.htm" > Libraries</ a ></ td >
2008-07-17 23:59:22 +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-06 12:13:52 +00:00
< td align = "center" >< a href = "../../../../../more/index.htm" > More</ a ></ td >
</ tr ></ table >
< hr >
< div class = "spirit-nav" >
2007-12-20 23:28:26 +00:00
< a accesskey = "p" href = "adapted/adapt_assoc.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 = "algorithm/iteration.html" >< img src = "../../../../../doc/html/images/next.png" alt = "Next" ></ a >
2007-11-06 12:13:52 +00:00
</ div >
2009-09-25 00:21:53 +00:00
< div class = "section" title = "Algorithm" >
< div class = "titlepage" >< div >< div >< h2 class = "title" style = "clear: both" >
< a name = "fusion.algorithm" ></ a >< a class = "link" href = "algorithm.html" title = "Algorithm" > Algorithm</ a >
</ h2 ></ div ></ div ></ div >
2007-11-06 12:13:52 +00:00
< div class = "toc" >< dl >
< dt >< span class = "section" >< a href = "algorithm/iteration.html" > Iteration</ a ></ span ></ dt >
< dd >< dl >
< dt >< span class = "section" >< a href = "algorithm/iteration/functions.html" > Functions</ a ></ span ></ dt >
< dt >< span class = "section" >< a href = "algorithm/iteration/metafunctions.html" > Metafunctions</ a ></ span ></ dt >
</ dl ></ dd >
< dt >< span class = "section" >< a href = "algorithm/query.html" > Query</ a ></ span ></ dt >
< dd >< dl >
< dt >< span class = "section" >< a href = "algorithm/query/functions.html" > Functions</ a ></ span ></ dt >
< dt >< span class = "section" >< a href = "algorithm/query/metafunctions.html" > Metafunctions</ a ></ span ></ dt >
</ dl ></ dd >
< dt >< span class = "section" >< a href = "algorithm/transformation.html" > Transformation</ a ></ span ></ dt >
< dd >< dl >
< dt >< span class = "section" >< a href = "algorithm/transformation/functions.html" > Functions</ a ></ span ></ dt >
< dt >< span class = "section" >< a href = "algorithm/transformation/metafunctions.html" > Metafunctions</ a ></ span ></ dt >
</ dl ></ dd >
</ dl ></ div >
2009-09-25 00:21:53 +00:00
< a name = "fusion.algorithm.lazy_evaluation" ></ a >< h4 >
2009-12-28 17:45:42 +00:00
< a name = "id752896" ></ a >
2009-09-25 00:21:53 +00:00
< a class = "link" href = "algorithm.html#fusion.algorithm.lazy_evaluation" > Lazy Evaluation</ a >
</ h4 >
2007-11-06 12:13:52 +00:00
< p >
Unlike < a href = "http://www.boost.org/libs/mpl/index.html" target = "_top" > MPL</ a > , Fusion
algorithms are lazy and non sequence-type preserving. What does that mean?
It means that when you operate on a sequence through a Fusion algorithm that
returns a sequence, the sequence returned may not be of the same class as the
original. This is by design. Runtime efficiency is given a high priority. Like
< a href = "http://www.boost.org/libs/mpl/index.html" target = "_top" > MPL</ a > , and unlike
< a href = "http://en.wikipedia.org/wiki/Standard_Template_Library" target = "_top" > STL</ a > ,
fusion algorithms are functional in nature such that algorithms are non mutating
(no side effects). However, due to the high cost of returning full sequences
such as vectors and lists, < span class = "emphasis" >< em > Views</ em ></ span > are returned from Fusion
2009-09-25 00:21:53 +00:00
algorithms instead. For example, the < a class = "link" href = "algorithm/transformation/functions/transform.html" title = "transform" >< code class = "computeroutput" >< span class = "identifier" > transform</ span ></ code ></ a > algorithm does not actually
return a transformed version of the original sequence. < a class = "link" href = "algorithm/transformation/functions/transform.html" title = "transform" >< code class = "computeroutput" >< span class = "identifier" > transform</ span ></ code ></ a > returns a < a class = "link" href = "view/transform_view.html" title = "transform_view" >< code class = "computeroutput" >< span class = "identifier" > transform_view</ span ></ code ></ a > . This view holds a
2007-11-06 12:13:52 +00:00
reference to the original sequence plus the transform function. Iteration over
2009-09-25 00:21:53 +00:00
the < a class = "link" href = "view/transform_view.html" title = "transform_view" >< code class = "computeroutput" >< span class = "identifier" > transform_view</ span ></ code ></ a >
2007-11-06 12:13:52 +00:00
will apply the transform function over the sequence elements on demand. This
< span class = "emphasis" >< em > lazy</ em ></ span > evaluation scheme allows us to chain as many algorithms
as we want without incurring a high runtime penalty.
</ p >
2009-09-25 00:21:53 +00:00
< a name = "fusion.algorithm.sequence_extension" ></ a >< h4 >
2009-12-28 17:45:42 +00:00
< a name = "id752973" ></ a >
2009-09-25 00:21:53 +00:00
< a class = "link" href = "algorithm.html#fusion.algorithm.sequence_extension" > Sequence Extension</ a >
</ h4 >
2007-11-06 12:13:52 +00:00
< p >
2009-09-25 00:21:53 +00:00
The < span class = "emphasis" >< em > lazy</ em ></ span > evaluation scheme where < a class = "link" href = "algorithm.html" title = "Algorithm" > Algorithms</ a >
return < a class = "link" href = "view.html" title = "View" > Views</ a > also allows operations such
as < a class = "link" href = "algorithm/transformation/functions/push_back.html" title = "push_back" >< code class = "computeroutput" >< span class = "identifier" > push_back</ span ></ code ></ a > to be totally generic. In
Fusion, < a class = "link" href = "algorithm/transformation/functions/push_back.html" title = "push_back" >< code class = "computeroutput" >< span class = "identifier" > push_back</ span ></ code ></ a > is actually a generic algorithm
that works on all sequences. Given an input sequence < code class = "computeroutput" >< span class = "identifier" > s</ span ></ code >
and a value < code class = "computeroutput" >< span class = "identifier" > x</ span ></ code > , Fusion's < a class = "link" href = "algorithm/transformation/functions/push_back.html" title = "push_back" >< code class = "computeroutput" >< span class = "identifier" > push_back</ span ></ code ></ a > algorithm simply returns
a < a class = "link" href = "view/joint_view.html" title = "joint_view" >< code class = "computeroutput" >< span class = "identifier" > joint_view</ span ></ code ></ a > :
a view that holds a reference to the original sequence < code class = "computeroutput" >< span class = "identifier" > s</ span ></ code >
and the value < code class = "computeroutput" >< span class = "identifier" > x</ span ></ code > . Functions
2007-11-06 12:13:52 +00:00
that were once sequence specific and need to be implemented N times over N
different sequences are now implemented only once. That is to say that Fusion
sequences are cheaply extensible. However, an important caveat is that the
2009-09-25 00:21:53 +00:00
result of a sequence extending operation like < a class = "link" href = "algorithm/transformation/functions/push_back.html" title = "push_back" >< code class = "computeroutput" >< span class = "identifier" > push_back</ span ></ code ></ a > does not retain the properties
of the original sequence such as associativity of < a class = "link" href = "container/set.html" title = "set" >< code class = "computeroutput" >< span class = "identifier" > set</ span ></ code ></ a > (s). To regain the original sequence,
< a class = "link" href = "container/conversion/functions.html" title = "Functions" > Conversion</ a > functions
are provided. You may use one of the < a class = "link" href = "container/conversion/functions.html" title = "Functions" > Conversion</ a >
2007-11-06 12:13:52 +00:00
functions to convert back to the original sequence type.
</ p >
2009-09-25 00:21:53 +00:00
< a name = "fusion.algorithm.header" ></ a >< h4 >
2009-12-28 17:45:42 +00:00
< a name = "id753100" ></ a >
2009-09-25 00:21:53 +00:00
< a class = "link" href = "algorithm.html#fusion.algorithm.header" > Header</ a >
</ h4 >
2009-02-22 06:27:12 +00:00
< pre class = "programlisting" >< span class = "preprocessor" > #include</ span > < span class = "special" > < </ span >< span class = "identifier" > boost</ span >< span class = "special" > /</ span >< span class = "identifier" > fusion</ span >< span class = "special" > /</ span >< span class = "identifier" > algorithm</ span >< span class = "special" > .</ span >< span class = "identifier" > hpp</ span >< span class = "special" > > </ span >
2007-11-06 12:13:52 +00:00
< span class = "preprocessor" > #include</ span > < span class = "special" > < </ 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" > algorithm</ span >< span class = "special" > .</ span >< span class = "identifier" > hpp</ span >< span class = "special" > > </ span >
</ pre >
</ div >
< table xmlns:rev = "http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width = "100%" >< tr >
< td align = "left" ></ td >
2009-12-11 21:01:22 +00:00
< td align = "right" >< div class = "copyright-footer" > Copyright © 2001-2007 Joel de Guzman, Dan Marsden, Tobias
2007-11-07 02:12:28 +00:00
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 > )
2007-11-14 10:17:09 +00:00
</ p >
</ div ></ td >
2007-11-06 12:13:52 +00:00
</ tr ></ table >
< hr >
< div class = "spirit-nav" >
2007-12-20 23:28:26 +00:00
< a accesskey = "p" href = "adapted/adapt_assoc.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 = "algorithm/iteration.html" >< img src = "../../../../../doc/html/images/next.png" alt = "Next" ></ a >
2007-11-06 12:13:52 +00:00
</ div >
</ body >
</ html >