Boost logo

Boost :

Subject: Re: [boost] Interest in a list comprehension library?
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2010-12-21 03:09:05

On 19/12/2010 19:40, Brent Spillner wrote:
> I uploaded sample code to the Vault (in the "Miscellaneous/"
> directory) that provides a concise notation for list comprehensions.
> The comprehensions are evaluated lazily and can be used to populate a
> std::list, vector, or deque, appended to the same, inserted after a
> given iterator, or interpreted as a boost::range, including
> compatibility with BOOST_FOREACH. Containers, iterator-defined
> ranges, or nullary function objects can be used as generators, and
> arbitrary function objects can be used to specify filter conditions.

Can you explain the difference with the Boost.Range adaptors?

> For example, the Pythagorean Triples example from
> can be coded as
> std::vector< boost::tuple<int,int,int> > triples =_(x, y, z)[x<<=
> range(1, n), y<<= range(x, n), z<<= range(y, n), x*x + y*y == z*z];

Here is the approximation of this with Boost.Range :

auto r = combine(irange(1, n), irange(1, n), irange(1, n))
        | filtered(at_c<0>(_1)*at_c<0>(_1) + at_c<1>*at_c<1> ==

std::vector< boost::tuple<int, int, int> > triples(r.begin(), r.end());

It doesn't support tuples with an easy syntax like you do, and there is
no way to define dependencies between the tuple elements.

It is true Boost.Range is quite lacking in terms of range generators,
and maybe your solution is what we need.
It would be nice however, if it didn't reinvent the wheel and can be
based on Phoenix for the functional part.

Boost list run by bdawes at, gregod at, cpdaniel at, john at