Boost logo

Boost :

Subject: Re: [boost] Boost.Range too focused on iterators?
From: Stuart Dootson (stuart.dootson_at_[hidden])
Date: 2009-07-11 06:51:55


On Fri, Jul 10, 2009 at 7:09 PM, j j<jjjaccck_at_[hidden]> wrote:
> The boost range library makes ranges similar to the to the STL
> Container<http://www.sgi.com/Technology/STL/Container.html>concept. A
> Range provides
> *iterators* for accessing a half-open range [first,one_past_last) of
> elements and provides information about the number of elements in the Range.
>
> Wouldn't it be better if it could use *values* and iterators?
> eg
> template<class access> ostream& operator<<(ostream& out,const range<access>&
> in){
>  for(x temp=in.a;temp!=in.b;temp++)cout<<access()(temp);
>  return out;
> }
>
> //Later on in code
> //prints a range of numbers
> cout<<Range<no_deref >(0,8); //no_deref is a function object that returns a
> reference to its argument.
> //prints the contents of a range of iterators.
> string a="Hello World!";
> cout<<Range(a.begin(),a.end()) //defaults to deref which is a function
> object that derefences its argument with *

If you use something like a counting iterator
(http://www.boost.org/doc/libs/1_39_0/libs/iterator/doc/counting_iterator.html),
you can get the range you want just with iterator ranges. Iterators
are sufficiently generic and adaptable a concept to get pretty much
whatever range you want.

Stuart Dootson


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