
Boost : 
From: jsiek_at_[hidden]
Date: 20000913 14:57:36
Another approach is the begin(container), end(container) interface
that is in array_traits. Then you don't really need the Range
class... just use std::pair and have a range() function that returns a
pair.
template <class Iter>
Iter begin(std::pair<Iter,Iter>& r) { return r.first; }
template <class Iter>
Iter end(std::pair<Iter,Iter>& r) { return r.second; }
template <class Iter>
std::pair<Iter,Iter> range(Iter first, Iter last) {
return std::make_pair(first, last);
}
David Abrahams writes:
> That (layerd iterator) is interesting. I wonder how that might interact with
> iterator_adaptor?
>
> Also, I've been thinking how unweildy it is to write std::pair<T, T> for
> ranges, and how much expressive power is lost by writing "pair" instead of
> "range". Instead, I've been using the appended Range<> template (not
> boostified), which I derived from std::pair for some compatibility with
> existing uses of pair as a range. What's really missing from this class are
> all the operations for union, intersection, containment, etc. I've
> implemented these before, but that code is owned by a previous employer ;(.
>
> Does anyone else think this would be really useful? It might be worth
> fleshing out, if so.
>
> Dave
>
> template <class T>
> class Range : public std::pair<T, T>
> {
> typedef std::pair<T, T> Base;
> public:
> Range() {}
>
> explicit Range(const T& x)
> : Base(x, x) {}
>
> Range(const T& start, const T& finish)
> : Base(start, finish) {}
>
> T begin() const;
> T end() const;
> };
>
> template <class T>
> inline T Range<T>::begin() const
> {
> return this>first;
> }
>
> template <class T>
> inline T Range<T>::end() const
> {
> return this>second;
> }
>
> template <class T>
> inline Range<T> make_range(const T& start, const T& finish)
> {
> return Range<T>(start, finish);
> }
>
>
>
>
>
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk