forked from boostorg/fusion
https://svn.boost.org/svn/boost/trunk ........ r40862 | dave | 2007-11-06 15:39:09 -0800 (Tue, 06 Nov 2007) | 2 lines Added missing copyright/license ........ r40863 | djowel | 2007-11-06 18:12:28 -0800 (Tue, 06 Nov 2007) | 1 line added copyright and license info for each page. ........ r40864 | aaron_windsor | 2007-11-06 18:30:38 -0800 (Tue, 06 Nov 2007) | 1 line Shortening file name of a graph test to < 32 characters ........ r40865 | djowel | 2007-11-06 18:34:18 -0800 (Tue, 06 Nov 2007) | 1 line added license info in copyright notice at the footer ........ r40866 | djowel | 2007-11-06 19:06:23 -0800 (Tue, 06 Nov 2007) | 1 line added license info in copyright notice at the footer ........ r40867 | djowel | 2007-11-06 19:23:31 -0800 (Tue, 06 Nov 2007) | 1 line added license info in copyright notice at the footer ........ r40868 | djowel | 2007-11-06 19:25:59 -0800 (Tue, 06 Nov 2007) | 1 line added copyright and license info for each page. ........ r40869 | djowel | 2007-11-06 19:27:38 -0800 (Tue, 06 Nov 2007) | 1 line added license info in copyright notice at the footer ........ r40870 | djowel | 2007-11-06 19:30:01 -0800 (Tue, 06 Nov 2007) | 1 line added copyright and license info for each page. ........ r40871 | djowel | 2007-11-06 19:35:49 -0800 (Tue, 06 Nov 2007) | 1 line added copyright and license info for each page. ........ r40872 | djowel | 2007-11-06 19:37:51 -0800 (Tue, 06 Nov 2007) | 1 line added copyright and license info for each page. ........ r40873 | djowel | 2007-11-06 19:46:23 -0800 (Tue, 06 Nov 2007) | 1 line added copyright and license info for each page. ........ r40874 | chris_kohlhoff | 2007-11-06 22:49:36 -0800 (Tue, 06 Nov 2007) | 2 lines Add copyright notice. ........ r40875 | chris_kohlhoff | 2007-11-06 22:53:17 -0800 (Tue, 06 Nov 2007) | 2 lines Add myself as asio maintainer. ........ r40876 | chris_kohlhoff | 2007-11-06 23:23:53 -0800 (Tue, 06 Nov 2007) | 2 lines Add asio. ........ r40877 | joaquin | 2007-11-07 00:45:27 -0800 (Wed, 07 Nov 2007) | 1 line reapplied change at rev 40284 ........ r40878 | johnmaddock | 2007-11-07 02:07:08 -0800 (Wed, 07 Nov 2007) | 1 line Ooops, got the pp-logic wrong and disable long double support for all Unix platforms, instead of just Intel on Linux prior to version 10. ........ r40879 | johnmaddock | 2007-11-07 02:09:50 -0800 (Wed, 07 Nov 2007) | 1 line Fix calls to fpclassify so they don't trigger macro expansion when fpclassify is a macro. ........ r40880 | t_schwinger | 2007-11-07 02:14:42 -0800 (Wed, 07 Nov 2007) | 3 lines adds FunctionTypes ........ r40881 | johnmaddock | 2007-11-07 03:50:02 -0800 (Wed, 07 Nov 2007) | 1 line Change test (again) so that the range of values tested matches original test: last change started testing more extreme input values, which caused regressions on Mac OS X. ........ r40882 | johnmaddock | 2007-11-07 03:59:39 -0800 (Wed, 07 Nov 2007) | 3 lines Disabled use of long double when BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS is defined. Disabled special-double precision error rates when BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS is defined. ........ r40883 | johnmaddock | 2007-11-07 04:04:01 -0800 (Wed, 07 Nov 2007) | 1 line Oops get the name of test right! ........ r40884 | anthonyw | 2007-11-07 04:10:17 -0800 (Wed, 07 Nov 2007) | 1 line Added missing licence and copyright ........ r40885 | garcia | 2007-11-07 04:25:16 -0800 (Wed, 07 Nov 2007) | 2 lines added logging library. ........ r40886 | garcia | 2007-11-07 05:38:53 -0800 (Wed, 07 Nov 2007) | 2 lines Exception was accepted. ........ r40887 | fcacciola | 2007-11-07 06:12:15 -0800 (Wed, 07 Nov 2007) | 1 line Added explicit failures for newly discovered GCC const ref binding bug (see Ticket #1301) ........ [SVN r40891]
89 lines
5.2 KiB
Plaintext
89 lines
5.2 KiB
Plaintext
[/==============================================================================
|
|
Copyright (C) 2001-2007 Joel de Guzman, Dan Marsden, Tobias Schwinger
|
|
|
|
Use, modification and distribution is subject to the Boost Software
|
|
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
|
http://www.boost.org/LICENSE_1_0.txt)
|
|
===============================================================================/]
|
|
[section Introduction]
|
|
|
|
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 `vector<int>` can only hold
|
|
`int`s. A `list<X>` can only hold elements of type `X`, and so on.
|
|
|
|
True, you can use inheritance to make the containers hold different types,
|
|
related through subclassing. However, you have to hold the objects through
|
|
a pointer or smart reference of some sort. Doing this, you'll have to rely
|
|
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 `char`, `int`, `class X`, `float`, etc. Oh sure you
|
|
can use something like __boost_any__ 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 to perform dangerous casts to get
|
|
back the original type.
|
|
|
|
The __tuple__ library written by __jaakko_jarvi__ provides heterogeneous
|
|
containers in C++. The `tuple` 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 and return types. As it
|
|
is, the __tuple__ facility is already very useful. Yet, as soon as you use
|
|
it more often, usage patterns emerge. Eventually, you collect these
|
|
patterns into algorithm libraries.
|
|
|
|
Hmmm, kinda reminds us of STL right? Right! Can you imagine how it would be
|
|
like if you used STL without the algorithms? Everyone will have to reinvent
|
|
their own /algorithm/ wheels.
|
|
|
|
Fusion is a library and a framework similar to both __stl__ and the boost
|
|
__mpl__. The structure is modeled after __mpl__, which is modeled
|
|
after __stl__. It is named "fusion" because the library is reminiscent of
|
|
the "fusion" of compile time meta-programming with runtime programming. The
|
|
library inherently has some interesting flavors and characteristics of both
|
|
__mpl__ and __stl__. It lives in the twilight zone between compile time
|
|
meta-programming and run time programming. __stl__ containers work on
|
|
values. MPL containers work on types. Fusion containers work on both types
|
|
and values.
|
|
|
|
Unlike __mpl__, 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 __mpl__, and unlike
|
|
__stl__, 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, /Views/ are returned
|
|
from Fusion algorithms instead. For example, the __transform__ algorithm
|
|
does not actually return a transformed version of the original sequence.
|
|
__transform__ returns a __transform_view__. This view holds a reference to
|
|
the original sequence plus the transform function. Iteration over the
|
|
__transform_view__ will apply the transform function over the sequence
|
|
elements on demand. This /lazy/ evaluation scheme allows us to chain as
|
|
many algorithms as we want without incurring a high runtime penalty.
|
|
|
|
The /lazy/ evaluation scheme where algorithms return views allows
|
|
operations such as __push_back__ to be totally generic. In Fusion,
|
|
__push_back__ is actually a generic algorithm that works on all sequences.
|
|
Given an input sequence `s` and a value `x`, Fusion's __push_back__
|
|
algorithm simply returns a __joint_view__: a view that holds a reference to
|
|
the original sequence `s` and the value `x`. Functions that were once
|
|
sequence specific and need to be implemented N times over N different
|
|
sequences are now implemented only once.
|
|
|
|
Fusion provides full round compatibility with __mpl__. Fusion sequences are
|
|
fully conforming __mpl__ sequences and __mpl__ sequences are fully
|
|
compatible with Fusion. You can work with Fusion sequences on __mpl__ if
|
|
you wish to work solely on types. In __mpl__, Fusion sequences follow
|
|
__mpl__'s sequence-type preserving semantics (i.e. algorithms preserve the
|
|
original sequence type. e.g. transforming a vector returns a vector). You
|
|
can also convert from an __mpl__ sequence to a Fusion sequence. For
|
|
example, there are times when it is convenient to work solely on __mpl__
|
|
using pure __mpl__ sequences, then, convert them to Fusion sequences as a
|
|
final step before actual instantiation of real runtime objects with data.
|
|
You have the best of both worlds.
|
|
|
|
[endsect]
|