From -1671786647998386064
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,8d7ae4b2a3e77f8b,start
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2003-08-07 20:22:31 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!kibo.news.demon.net!mutlu.news.demon.net!demon!mail2news.demon.co.uk!devnull
From: stefan_heinzmann@yahoo.com (Stefan Heinzmann)
Newsgroups: comp.std.c++
Subject: Why is there no range type in the standard library?
Date: Fri, 8 Aug 2003 03:22:27 +0000 (UTC)
Organization: http://groups.google.com/
Lines: 49
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <95e0e5ef.0308060330.28aefaae@posting.google.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: mail2news.demon.co.uk 1060312947 22633 10.0.0.1 (8 Aug 2003 03:22:27 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Fri, 8 Aug 2003 03:22:27 +0000 (UTC)
X-Received: from mulga.cs.mu.oz.au ([128.250.1.22])
	by news.demon.co.uk with esmtp (Exim 4.12)
	id 19kxpi-0005su-00
	for mail2news@news.news.demon.net; Fri, 08 Aug 2003 03:22:26 +0000
X-Received: from localhost (localhost [[UNIX: localhost]]) by mulga.cs.mu.OZ.AU
	id NAA00362; Fri, 8 Aug 2003 13:22:23 +1000 (EST)
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Path: comp-std-cpp-robomod!not-for-mail
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Delivered-To: std-c++@ucar.edu
X-Newsgroups: comp.std.c++
X-NNTP-Posting-Date: 6 Aug 2003 11:30:55 GMT
X-Spam-Status: No, hits=-2.7 required=5.0
	tests=BAYES_01,FORGED_YAHOO_RCVD
	version=2.55
X-Spam-Checker-Version: SpamAssassin 2.55 (1.174.2.19-2003-05-19-exp)
Xref: archiver1.google.com comp.std.c++:20513

Hi all,

this may have surfaced in the past, but I don't know what the current
wisdom is, so please forgive me if I'm asking a FAQ and point me to
the relevant docs.

Given that the notion of an iterator range is rather fundamental in
the standard library, I wonder why this wasn't turned into a class
template in the STL. Something like this:

template<typename Iter>
struct iterator_range {
    Iter begin, end;

    size_t size() const { return std::distance(begin,end); }
    bool empty() const { return begin == end; }
    bool operator==(const Iter& rhs) const
        { return (begin == rhs.begin) && (end == rhs.end); }
    // ... potentially more methods here
};

template<typename Iter>
iterator_range<Iter> range(const Iter& b, const Iter& e)
{
    iterator_range<Iter> res = { b,e };
    return res;
}


Wouldn't that make the usage of standard algorithms and standard
containers both easier and safer? Ideally, each container wouldn't
just define its iterator type but also its iterator range type through
a typedef. Algorithms operating on a range would not take two separate
iterator arguments but a single range argument instead.

Is this omission the result of a deliberate decision of the standards
committee, and if so, what was the rationale? Or if not, is the
addition of such a definition under consideration for the next version
of the standard?

Cheers
Stefan

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



