Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2004-05-01 08:28:56


Dave Gomboc wrote:
>I'm revisiting Czarnecki and Eisenecker's work (Generative Programming:
>Methods, Tools, and Applications) from 2000. I'm wondering what is
>available in boost that exploits (or even advances) on the techniques
>and code examples given there.

>It occurs to me that both the concept_check and the mpl library have
>something to offer in this respect. At the very least, there are few
>obvious things (e.g. if, apply_if, etc. in mpl). Is anyone actively
>applying boost code in this area?

Have you had a look at Boost.Spirit and the related Phoenix/Fusion
libraries? Spirit is a lexer/parser generator that allows you to write BNF
grammars in C++ that are close to the actual BNF grammar declerations, as
well as providing a set of grammar recognisers like real numbers. See the
documentation for more information.

Spirit allows you to bind actions to the grammar (e.g. summing the numbers
read from a file/user input). There is closure support, alliowing a grammar
rule to have data bound to it, and the Phoenix/Fusion library provides a
mechanism for writing lazily evaluated C++-like code (e.g. if, while as well
as STL actions such as push_back and assign).

e.g.
   std::vector< float > v;
   ...
   rule<> = real_p[ push_back_p( v ) ] >> ',' >> real_p[ push_back_p( v ) ]

NOTE: The Spirit documentation contains this example with a more detailed
explanation.

There is also the Lambda library - which is currently being rewritten to sit
on top of the Fusion framework - that allows you to use Lambda expressions
in C++ code, e.g.:

   std::for_each( c.begin(), c.end(), n += _1 ); // see Lambda docs for
correct usage

There has also been a review of the FC++ library (see the mail archives for
details) that attempts to provide a functional language framework, and
although it has not yet been accepted into Boost, there are some powerful
concepts like Lazy Lists. It provides its own Lambda implementation and
equivalent of Boost.Function/Boost,Bind. Even though this is functional
programming (like Haskell) there is a heavy reliance on template
metaprogramming as well as adding to the existing generative framework.

If you want to find out how extensively the MPL library is used in Boost, do
a search for "mpl::". I know that the Serialisation library is using it.
Also, there are several workarounds for the current lack of typeof/auto in
various libraries that need it.

My I/O formatters library (boost-sandbox/outfmt) uses a technique similar to
this to map a type to a classification (e.g. container, array, n-ary) in
order to build the appropriate formatter so that it can be correctly written
to/read from a C++ stream. The documentation is currently out of synch with
the implementation and examples, but I am revising it at the moment.

Also, the STL provides generative support with iterators/iterator_traits,
algorithms and functors. The Boost library has enhanced these with the
Iterator Adaptors library, a better iterator_traits and other stuff.

Hope that helped.

Regards,
Reece

_________________________________________________________________
Express yourself with cool emoticons - download MSN Messenger today!
http://www.msn.co.uk/messenger


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk