Boost logo

Boost :

Subject: Re: [boost] tie alternative?
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2008-10-30 06:34:18


2008/10/27 David Abrahams <dave_at_[hidden]>

> OK, BOOST_FOREACH aside, iterating over a range returned as a pair of
> iterators can be painful and ugly:
>
> vertex_iterator pv, ve;
> tie(pv, ve) = vertices(g); // unpack the pair returned by vertices
> for (; pv != pe; ++pv)
> {
> ...
> }
>
> However, we can make it much nicer, e.g.:
>
> for (vertex_iterator pv,ve = xxx(pv,vertices(g)); pv != ve; ++pv)
> {
> ...
> }
>
> My only problem is how to spell xxx. The attached proof-of-concept uses
> operator%, but I don't feel particularly good about that choice either.
> Ideas?
>
>
You probably know this already, but this functionality is almost covered by
the RangeEx
proposal in the vault. However, since it's not part of Boost yet, how about
anticipating
the RangeEx route and adding a, possibly local, templated for_each(...) for
a
range pair. Just a thought since every alternative seems to have drawbacks.

- Rob.


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