Boost logo

Boost :

From: Michiel Salters (Michiel.Salters_at_[hidden])
Date: 2002-02-21 10:24:47


> -----Original Message-----
> From: David Abrahams [mailto:david.abrahams_at_[hidden]]
> Sent: donderdag 21 februari 2002 14:29
> To: boost_at_[hidden]
> Subject: Re: [boost] Re: Most needed/desired features in C++
>
>
>
> ----- Original Message -----
> From: "Michiel Salters" <Michiel.Salters_at_[hidden]>
>
> > Is there a reason you want to have an end iterator, instead of an
> > at_end( iterator ) function ? Implementing the latter in
> terms of the
> > former is trivial, but all you have is the at_end( )
> functionality, you
> > need a special singular iterator to signal at_end( ), which can make
> > all iterators bigger. Furthermore, for many output
> iterators, at_end( )
> > is trivially implemented as "return false;". The corresponding
> > iterator is much more work.
>
> I can think of several huge problems with at_end():
>
> * How do you iterate over a subrange?
> * Is a pointer still an iterator? How do you write at_end()
> for pointers?
>
> -Dave

Seems simple to me:

template < typename ITERATOR >
class SubRange {
ITERATOR b,e;
public:
  SubRange ( ITERATOR b, ITERATOR e );
  bool at_end( ITERATOR i ) { return i==e; }
};

templae < typename T >
class PtrRange : public SubRange<T*>
{
  // Perhaps some special-purpose ctors?
}

My point was that if you have any end iterator, at_end( ) is trivial.
The other way around is much harder - you often need an extra
data member to create a singular iterator for the end condition.

-- 
Michiel Salters

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