Boost logo

Boost :

From: Alexander Nasonov (alnsn-mycop_at_[hidden])
Date: 2004-04-22 14:33:28


Anatoli Tubman wrote:

> Another option is to write
>
> for (crange<int>& r = mkrange(d); r; ++r) { ... }
Small correction
for (crange<int> *const* & r = mkrange(d); r; ++r) { ... }

> where mkrange returns crange_impl<int, d_array> which is derived from
> crange<int>.
Slicing problem should be solved because it's easy to forget & between
crange<int> and r. I wish we were able to typedef a reference to
'crange_impl<int, d_array> const' as crange<int>.

> This doesn't need heap allocation, but still needs virtual operator++
> and virtual operator*. A smart compiler could in theory inline them
> anyway, but I wouldn't count on it.
I hope they will follow if we ever decided to accept the approach ;-)

Later this approach could be changed either to

for (auto r = mkrange(d); r; ++r) { ... }
// TODO: correct the idea if auto strip top-level reference off

or direct compiler support of foreach construct.

-- 
Alexander Nasonov
Independent Developer and Consultant

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