Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2003-11-04 04:06:38


Thorsten Ottosen wrote:
> David write:
> > It should only be called "range" if it's meant to work on ranges of
> > non-iterators. But then, you should call it half_open_range ;-)
>
> 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;
> };

Personally, I don't think it's a good idea to have member functions named
'begin'/'end' that don't return iterators. That's one reason why one might
want a range to be a different beast from iterator range.

>
> 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
>
> [begin,end)
>
> where 'begin' is included and 'end' is not. If the argument for not using
> the name range for the class is that many different types of ranges exist,
> then
> we should consider if that is a good thing with these many ranges.

FWIW, a lot of user input comes in the form of closed ranges (e.g. dates,
pages, etc.).

> IMO, it
> is not a good thing because all the ranges can be used to describe
> eachother:
>
> [begin,end] = [begin, end + 1 )
> (begin, end) = [begin +1, end )
> (begin, end] = [begin + 1, end + 1 )
>
> To me it seems that it shall only be necessary with one type of range.
> Bringing more into the picture will only bring confusion.
>
> Aleksey, what do you use the different range types to at your work?

Yes, we use both half-open and closed ranges - the latter for the use cases
I cited above.

Aleksey


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