Boost logo

Boost :

Subject: [boost] [variadic_templates][mpl]announcement:sandbox now has variadic_templates directory
From: Larry Evans (cppljevans_at_[hidden])
Date: 2009-09-12 14:38:14


There is now a sandbox directory for variadic templates:

   https://svn.boost.org/trac/boost/browser/sandbox/variadic_templates

The tests in variadic_templates/libs/mpl/test/Jamfile have all passed.
Some of those tests have been slightly modified to accommodate the
variadic template version of mpl sequences.

BTW, it's important to apply the gcc patch mentioned here:

 
https://svn.boost.org/trac/boost/browser/sandbox/variadic_templates/README.compiler_requirements.txt

All sequences have been changed to use a new template:

   foldr_pack

whose last argument is a parameter pack. That change also required
a new binary template for each sequence:

   X_item_fold

where X is one of:

   v
   l
   s
   m

One reason for that change was to highlight the similarites of
the sequences.

Some other fold additions were:

   foldr_iter.hpp
   foldl_iter.hpp

The foldr and foldl correspond roughly to iter_fold and
reverse_iter_fold (or the other way around, I can't remember which).
The reason for these additions is that they reflect more closely the
way foldr and foldl are done in haskell, as indicated by the comments
in the .hpp files.

One useful application of the pattern expansion mentioned in section
3.6.1 of:

   http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2242.pdf

is their use to easily define SEQ_c in terms of SEQ, where SEQ is any
sequence. For example:

   template
   < typename Integral
   , Integral... Values
>
   struct
list_c
   : list
     < integral_c<Integral,Values>...
>
{
     typedef Integral value_type;
};

Another addition is package_range_c.hpp which can be used to do
something similar to range_c. The main motivation for this was the
make_indexes on p. 16 of:

   http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2006/n2080.pdf

It was used in a prototype tuple implementation in:

   variadic_templates/libs/mpl/sandbox/tuple_non_recur.package_range_c.cpp

Package_range_c was also useful in the implementation of unpack_args.

A really interesting application of these pattern expansions might be
another implementation of the cross_product template:

 
http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?CPPTM_Answers_-_Exercise_7-8

The reason I think it would be useful is because the expansion of:

   integral_c<Integral,Values>...

results in:

   integral_c<Integral,Value1>
   integral_c<Integral,Value2>
   ...
   integral_c<Integral,ValueN>

where ValueI is the i-th element in Values...
Now this is a cross product of a single element, Integral, with each
element in Values...; hence, I would think that it would be a simple
matter to just repeat this for any number of elements. IOW, instead
of integral_c, there could be:

   template<typename Left, typename...Rights>
   struct pair_rights
   : pair<Left,Rights>...
   {};

and then that, somehow, could be done for each element in some list of
Left's. Would somebody like to try this?

Hope somebody else finds this useful.

-regards,
Larry


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