forked from boostorg/fusion
introduces documentation for deduce / deduce_sequence
[SVN r36813]
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Introduction</title>
|
||||
<link rel="stylesheet" href="../boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.66.1">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.68.1">
|
||||
<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">
|
||||
<link rel="prev" href="preface.html" title="Preface">
|
||||
@ -29,9 +29,9 @@
|
||||
An advantage other languages such as Python and Lisp/ Scheme, ML and Haskell,
|
||||
etc., over C++ is the ability to have heterogeneous containers that can hold
|
||||
arbitrary element types. All the containers in the standard library can only
|
||||
hold a specific type. A <tt class="computeroutput"><span class="identifier">vector</span><span class="special"><</span><span class="keyword">int</span><span class="special">></span></tt>
|
||||
can only hold <tt class="computeroutput"><span class="keyword">int</span></tt>s. A <tt class="computeroutput"><span class="identifier">list</span><span class="special"><</span><span class="identifier">X</span><span class="special">></span></tt> can
|
||||
only hold elements of type <tt class="computeroutput"><span class="identifier">X</span></tt>,
|
||||
hold a specific type. A <code class="computeroutput"><span class="identifier">vector</span><span class="special"><</span><span class="keyword">int</span><span class="special">></span></code>
|
||||
can only hold <code class="computeroutput"><span class="keyword">int</span></code>s. A <code class="computeroutput"><span class="identifier">list</span><span class="special"><</span><span class="identifier">X</span><span class="special">></span></code> can
|
||||
only hold elements of type <code class="computeroutput"><span class="identifier">X</span></code>,
|
||||
and so on.
|
||||
</p>
|
||||
<p>
|
||||
@ -41,8 +41,8 @@
|
||||
on virtual functions to provide polymorphic behavior since the actual type
|
||||
is erased as soon as you store a pointer to a derived class to a pointer to
|
||||
its base. The held objects must be related: you cannot hold objects of unrelated
|
||||
types such as <tt class="computeroutput"><span class="keyword">char</span></tt>, <tt class="computeroutput"><span class="keyword">int</span></tt>, <tt class="computeroutput"><span class="keyword">class</span>
|
||||
<span class="identifier">X</span></tt>, <tt class="computeroutput"><span class="keyword">float</span></tt>,
|
||||
types such as <code class="computeroutput"><span class="keyword">char</span></code>, <code class="computeroutput"><span class="keyword">int</span></code>, <code class="computeroutput"><span class="keyword">class</span>
|
||||
<span class="identifier">X</span></code>, <code class="computeroutput"><span class="keyword">float</span></code>,
|
||||
etc. Oh sure you can use something like <a href="http://boost.org/doc/html/any.html" target="_top">Boost.Any</a>
|
||||
to hold arbitrary types, but then you pay more in terms of runtime costs and
|
||||
due to the fact that you practically erased all type information, you'll have
|
||||
@ -51,7 +51,7 @@
|
||||
<p>
|
||||
The <a href="http://www.boost.org/libs/tuple/doc/tuple_users_guide.html" target="_top">Boost.Tuple</a>
|
||||
library written by <a href="http://www.boost.org/people/jaakko_jarvi.htm" target="_top">Jaakko
|
||||
Jarvi</a> provides heterogeneous containers in C++. The <tt class="computeroutput"><span class="identifier">tuple</span></tt>
|
||||
Jarvi</a> provides heterogeneous containers in C++. The <code class="computeroutput"><span class="identifier">tuple</span></code>
|
||||
is a basic data structure that can hold heterogeneous types. It's a good first
|
||||
step, but it's not complete. What's missing are the algorithms. It's nice that
|
||||
we can store and retrieve data to and from tuples, pass them around as arguments
|
||||
@ -89,23 +89,23 @@
|
||||
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
|
||||
algorithms instead. For example, the <a href="algorithms/transformation/functions/transform.html" title="transform"><tt class="computeroutput"><span class="identifier">transform</span></tt></a> algorithm does not actually
|
||||
return a transformed version of the original sequence. <a href="algorithms/transformation/functions/transform.html" title="transform"><tt class="computeroutput"><span class="identifier">transform</span></tt></a> returns a <a href="sequences/views/transform_view.html" title="transform_view"><tt class="computeroutput"><span class="identifier">transform_view</span></tt></a>. This view holds a
|
||||
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
|
||||
reference to the original sequence plus the transform function. Iteration over
|
||||
the <a href="sequences/views/transform_view.html" title="transform_view"><tt class="computeroutput"><span class="identifier">transform_view</span></tt></a>
|
||||
the <a href="sequences/views/transform_view.html" title="transform_view"><code class="computeroutput"><span class="identifier">transform_view</span></code></a>
|
||||
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>
|
||||
<p>
|
||||
The <span class="emphasis"><em>lazy</em></span> evaluation scheme where algorithms return views
|
||||
allows operations such as <a href="algorithms/transformation/functions/push_back.html" title="push_back"><tt class="computeroutput"><span class="identifier">push_back</span></tt></a> to be totally generic. In
|
||||
Fusion, <a href="algorithms/transformation/functions/push_back.html" title="push_back"><tt class="computeroutput"><span class="identifier">push_back</span></tt></a> is actually a generic algorithm
|
||||
that works on all sequences. Given an input sequence <tt class="computeroutput"><span class="identifier">s</span></tt>
|
||||
and a value <tt class="computeroutput"><span class="identifier">x</span></tt>, Fusion's <a href="algorithms/transformation/functions/push_back.html" title="push_back"><tt class="computeroutput"><span class="identifier">push_back</span></tt></a> algorithm simply returns
|
||||
a <a href="sequences/views/joint_view.html" title="joint_view"><tt class="computeroutput"><span class="identifier">joint_view</span></tt></a>:
|
||||
a view that holds a reference to the original sequence <tt class="computeroutput"><span class="identifier">s</span></tt>
|
||||
and the value <tt class="computeroutput"><span class="identifier">x</span></tt>. Functions
|
||||
allows operations 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
|
||||
that were once sequence specific and need to be implemented N times over N
|
||||
different sequences are now implemented only once.
|
||||
</p>
|
||||
|
Reference in New Issue
Block a user