2006-08-22 15:57:13 +00:00
< html >
< head >
< meta http-equiv = "Content-Type" content = "text/html; charset=ISO-8859-1" >
< title > Algorithms</ title >
< link rel = "stylesheet" href = "../boostbook.css" type = "text/css" >
2007-02-15 23:11:24 +00:00
< meta name = "generator" content = "DocBook XSL Stylesheets V1.68.1" >
2006-08-22 15:57:13 +00:00
< link rel = "start" href = "../index.html" title = "Chapter 1. Fusion 2.0" >
< link rel = "up" href = "../index.html" title = "Chapter 1. Fusion 2.0" >
< link rel = "prev" href = "sequences/operators/comparison/greater_than_equal.html" title = "greater
than equal" >
2007-02-15 23:11:24 +00:00
< link rel = "next" href = "algorithms/iteration.html" title = "Iteration" >
2006-08-22 15:57:13 +00:00
</ head >
< body bgcolor = "white" text = "black" link = "#0000FF" vlink = "#840084" alink = "#0000FF" >
< table cellpadding = "2" width = "100%" >
< td valign = "top" >< img alt = "Boost C++ Libraries" width = "277" height = "86" src = "../../../../../boost.png" ></ td >
< td align = "center" >< a href = "../../../../../index.htm" > Home</ a ></ td >
< td align = "center" >< a href = "../../../../libraries.htm" > Libraries</ a ></ td >
< td align = "center" >< a href = "../../../../../people/people.htm" > People</ a ></ td >
< td align = "center" >< a href = "../../../../../more/faq.htm" > FAQ</ a ></ td >
< td align = "center" >< a href = "../../../../../more/index.htm" > More</ a ></ td >
</ table >
< hr >
< div class = "spirit-nav" >
2007-02-15 23:11:24 +00:00
< a accesskey = "p" href = "sequences/operators/comparison/greater_than_equal.html" >< img src = "../images/prev.png" alt = "Prev" ></ a >< a accesskey = "u" href = "../index.html" >< img src = "../images/up.png" alt = "Up" ></ a >< a accesskey = "h" href = "../index.html" >< img src = "../images/home.png" alt = "Home" ></ a >< a accesskey = "n" href = "algorithms/iteration.html" >< img src = "../images/next.png" alt = "Next" ></ a >
2006-08-22 15:57:13 +00:00
</ div >
< div class = "section" lang = "en" >
< div class = "titlepage" >< div >< div >< h2 class = "title" style = "clear: both" >
< a name = "fusion.algorithms" ></ a >< a href = "algorithms.html" title = "Algorithms" > Algorithms</ a ></ h2 ></ div ></ div ></ div >
< div class = "toc" >< dl >
< dt >< span class = "section" >< a href = "algorithms/iteration.html" > Iteration</ a ></ span ></ dt >
2007-01-22 00:40:36 +00:00
< dd >< dl >
< dt >< span class = "section" >< a href = "algorithms/iteration/functions.html" > Functions</ a ></ span ></ dt >
< dt >< span class = "section" >< a href = "algorithms/iteration/metafunctions.html" > Metafunctions</ a ></ span ></ dt >
</ dl ></ dd >
2006-08-22 15:57:13 +00:00
< dt >< span class = "section" >< a href = "algorithms/query.html" > Query</ a ></ span ></ dt >
2007-01-22 00:40:36 +00:00
< dd >< dl >
< dt >< span class = "section" >< a href = "algorithms/query/functions.html" > Functions</ a ></ span ></ dt >
< dt >< span class = "section" >< a href = "algorithms/query/metafunctions.html" > Metafunctions</ a ></ span ></ dt >
</ dl ></ dd >
2006-08-22 15:57:13 +00:00
< dt >< span class = "section" >< a href = "algorithms/transformation.html" > Transformation</ a ></ span ></ dt >
2007-01-22 00:40:36 +00:00
< dd >< dl >
< dt >< span class = "section" >< a href = "algorithms/transformation/functions.html" > Functions</ a ></ span ></ dt >
< dt >< span class = "section" >< a href = "algorithms/transformation/metafunctions.html" > Metafunctions</ a ></ span ></ dt >
</ dl ></ dd >
2006-08-22 15:57:13 +00:00
</ dl ></ div >
< a name = "fusion.algorithms.lazy_evaluation" ></ a >< h3 >
2007-07-13 19:25:34 +00:00
< a name = "id1113801" ></ a >
2006-08-22 15:57:13 +00:00
< a href = "algorithms.html#fusion.algorithms.lazy_evaluation" > Lazy Evaluation</ a >
</ h3 >
< 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
2007-02-15 23:11:24 +00:00
algorithms instead. For example, the < a href = "algorithms/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 href = "algorithms/transformation/functions/transform.html" title = "transform" >< code class = "computeroutput" >< span class = "identifier" > transform</ span ></ code ></ a > returns a < a href = "sequences/views/transform_view.html" title = "transform_view" >< code class = "computeroutput" >< span class = "identifier" > transform_view</ span ></ code ></ a > . This view holds a
2006-08-22 15:57:13 +00:00
reference to the original sequence plus the transform function. Iteration over
2007-02-15 23:11:24 +00:00
the < a href = "sequences/views/transform_view.html" title = "transform_view" >< code class = "computeroutput" >< span class = "identifier" > transform_view</ span ></ code ></ a >
2006-08-22 15:57:13 +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 >
< a name = "fusion.algorithms.sequence_extension" ></ a >< h3 >
2007-07-13 19:25:34 +00:00
< a name = "id1113934" ></ a >
2006-08-22 15:57:13 +00:00
< a href = "algorithms.html#fusion.algorithms.sequence_extension" > Sequence Extension</ a >
</ h3 >
< p >
The < span class = "emphasis" >< em > lazy</ em ></ span > evaluation scheme where < a href = "algorithms.html" title = "Algorithms" > Algorithms</ a >
return < a href = "sequences/views.html" title = "Views" > Views</ a > also allows operations
2007-02-15 23:11:24 +00:00
such as < a href = "algorithms/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 href = "algorithms/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 href = "algorithms/transformation/functions/push_back.html" title = "push_back" >< code class = "computeroutput" >< span class = "identifier" > push_back</ span ></ code ></ a > algorithm simply returns
a < a href = "sequences/views/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
2006-08-22 15:57:13 +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
2007-02-15 23:11:24 +00:00
result of a sequence extending operation like < a href = "algorithms/transformation/functions/push_back.html" title = "push_back" >< code class = "computeroutput" >< span class = "identifier" > push_back</ span ></ code ></ a > does not retain the properties
2006-08-22 15:57:13 +00:00
of the original sequence such as associativity of < span class = "underline" > _set</ span > _s.
To regain the original sequence, < a href = "sequences/conversion/functions.html" title = "Functions" > Conversion</ a >
functions are provided. You may use one of the < a href = "sequences/conversion/functions.html" title = "Functions" > Conversion</ a >
functions to convert back to the original sequence type.
</ p >
< a name = "fusion.algorithms.header" ></ a >< h3 >
2007-07-13 19:25:34 +00:00
< a name = "id1114134" ></ a >
2006-08-22 15:57:13 +00:00
< a href = "algorithms.html#fusion.algorithms.header" > Header</ a >
</ h3 >
< 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 >
</ pre >
</ div >
< table xmlns:rev = "http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width = "100%" >< tr >
< td align = "left" ></ td >
2007-02-25 22:02:27 +00:00
< td align = "right" >< small > Copyright © 2001-2007 Joel de Guzman, Dan Marsden, Tobias
Schwinger</ small ></ td >
2006-08-22 15:57:13 +00:00
</ tr ></ table >
< hr >
< div class = "spirit-nav" >
2007-02-15 23:11:24 +00:00
< a accesskey = "p" href = "sequences/operators/comparison/greater_than_equal.html" >< img src = "../images/prev.png" alt = "Prev" ></ a >< a accesskey = "u" href = "../index.html" >< img src = "../images/up.png" alt = "Up" ></ a >< a accesskey = "h" href = "../index.html" >< img src = "../images/home.png" alt = "Home" ></ a >< a accesskey = "n" href = "algorithms/iteration.html" >< img src = "../images/next.png" alt = "Next" ></ a >
2006-08-22 15:57:13 +00:00
</ div >
</ body >
</ html >