Boost logo

Boost :

From: Jeremy Siek (jsiek_at_[hidden])
Date: 2002-02-21 15:54:02

For what it's worth, I used something like these ranges Michiel is talking
about in the MTL 3 prototype. It turned out to be useful for handling
sparse vector iterators, especially when trying to compose two iterators
and a binary function (like multiplication) to form a single iterator.

On Thu, 21 Feb 2002, Michiel Salters wrote:
Michie> > -----Original Message-----
Michie> > From: David Abrahams [mailto:david.abrahams_at_[hidden]]
Michie> > Sent: donderdag 21 februari 2002 14:29
Michie> > To: boost_at_[hidden]
Michie> > Subject: Re: [boost] Re: Most needed/desired features in C++
Michie> >
Michie> >
Michie> >
Michie> > ----- Original Message -----
Michie> > From: "Michiel Salters" <Michiel.Salters_at_[hidden]>
Michie> >
Michie> > > Is there a reason you want to have an end iterator, instead of an
Michie> > > at_end( iterator ) function ? Implementing the latter in
Michie> > terms of the
Michie> > > former is trivial, but all you have is the at_end( )
Michie> > functionality, you
Michie> > > need a special singular iterator to signal at_end( ), which can make
Michie> > > all iterators bigger. Furthermore, for many output
Michie> > iterators, at_end( )
Michie> > > is trivially implemented as "return false;". The corresponding
Michie> > > iterator is much more work.
Michie> >
Michie> > I can think of several huge problems with at_end():
Michie> >
Michie> > * How do you iterate over a subrange?
Michie> > * Is a pointer still an iterator? How do you write at_end()
Michie> > for pointers?
Michie> >
Michie> > -Dave
Michie> Seems simple to me:
Michie> template < typename ITERATOR >
Michie> class SubRange {
Michie> ITERATOR b,e;
Michie> public:
Michie> SubRange ( ITERATOR b, ITERATOR e );
Michie> bool at_end( ITERATOR i ) { return i==e; }
Michie> };
Michie> templae < typename T >
Michie> class PtrRange : public SubRange<T*>
Michie> {
Michie> // Perhaps some special-purpose ctors?
Michie> }
Michie> My point was that if you have any end iterator, at_end( ) is trivial.
Michie> The other way around is much harder - you often need an extra
Michie> data member to create a singular iterator for the end condition.
Michie> --
Michie> Michiel Salters
Michie> Info: Send unsubscribe requests to: <mailto:boost-unsubscribe_at_[hidden]>
Michie> Your use of Yahoo! Groups is subject to

 Jeremy Siek
 Ph.D. Student, Indiana Univ. B'ton email: jsiek_at_[hidden]
 C++ Booster ( office phone: (812) 855-3608

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