Boost logo

Boost :

From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2003-11-03 04:14:36

> [snip]
> > I don't agree. The current interface seems compatible with any type of
> > ordered type:
> >
> > template< typename T >
> > class range
> > {
> > T begin() const;
> > T end() const;
> > T size() const;
> > bool empty() const;
> > };
> >
> > AFAICT, only size() needs to be specialized for integers which should be
> > easy using typetraits. So the same range class can easily support
> > both iterators and integers.
> >
> > Moreover, the standard uses half-open ranges of the type
> Actualy, it is not fully correct. 'iterator_range' is realy intended to
work with
> iterators only. Along with the operations you have specified, it has
> a set of typedefs and operations are implemented using iterator

I assume you mean

 typedef iterator_range< IteratorT > type;
// this type
  typedef boost::detail::iterator_traits< IteratorT >::value_type
value_type; // Encapsulated value type.
  typedef boost::detail::iterator_traits< IteratorT >::reference
reference; // Reference type.
  typedef boost::detail::iterator_traits< IteratorT >::difference_type
difference_type; // Difference type.
  typedef boost::detail::iterator_traits< IteratorT >::difference_type
size_type; // Size type.
  typedef IteratorT
const_iterator; // const_iterator type
  typedef IteratorT

AFAICT, the could be replaced by a single typedef 'value_type' and then you
can let the container traits
take care of the rest. This would also be good for compilation times.

About the operations, then size() should be the only one who need special
treatment. About
  1.. void reverse() ;Reverse the range.

  Reverse the range, i.e. swap begin and end

then I don't see why this should be. AFAICT, the class's invariant should be

'end' is reachable from 'begin' (or begin < end ).

If that is not the case, then we could get wierd results (so I really don't
get this). OTOH, if the class has no invariant, we might as well use


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