Boost logo

Boost :

From: Pavol Droba (droba_at_[hidden])
Date: 2003-11-03 04:51:23


On Mon, Nov 03, 2003 at 08:14:36PM +1100, Thorsten Ottosen wrote:

[snip]
> > 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
> > operations.
> >
> 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.

I don't know, how container traits could do all this. At least iterator and const_iterator
typedef must be present and this strongly implies iterator afinity.

> 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
> std::pair.

Sure, we can use std::pair. iterator_range is not supposed to add much more. Only I find
it a way more clean an easier to use, because, you need to specify only one template argument
(unlike in confusing pair) and the name denotes what is the semantic value of the contained
pair of iterators.

Adding additional functionality and meaning to the iterator_range will break its original
purpose.

Regards,

Pavol


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