From 6743431772514920745
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,8d7ae4b2a3e77f8b
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2003-08-12 19:10:32 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!kibo.news.demon.net!mutlu.news.demon.net!demon!mail2news.demon.co.uk!devnull
From: johnchx2@yahoo.com (johnchx)
Newsgroups: comp.std.c++
Subject: Re: Why is there no range type in the standard library?
Date: Wed, 13 Aug 2003 02:10:28 +0000 (UTC)
Organization: http://groups.google.com/
Lines: 51
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <4fb4137d.0308121536.76863b24@posting.google.com>
References: <95e0e5ef.0308060330.28aefaae@posting.google.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: mail2news.demon.co.uk 1060740629 7748 10.0.0.1 (13 Aug 2003 02:10:29 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Wed, 13 Aug 2003 02:10:29 +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 19ml5n-00020m-00
	for mail2news@news.news.demon.net; Wed, 13 Aug 2003 02:10:28 +0000
X-Received: from localhost (localhost [[UNIX: localhost]]) by mulga.cs.mu.OZ.AU
	id MAA27422; Wed, 13 Aug 2003 12:10:05 +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: 12 Aug 2003 23:36:08 GMT
X-Spam-Status: No, hits=-3.1 required=5.0
	tests=BAYES_01,FORGED_YAHOO_RCVD,QUOTED_EMAIL_TEXT,REFERENCES
	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++:20596

stefan_heinzmann@yahoo.com (Stefan Heinzmann) wrote 

> 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. 

Well, in a weak sense, it was: std::pair.  In the rare cases in which
an STL container member function actually returns a range (e.g.
std::multimap::equal_range()), a pair is what you get.

Why isn't std::pair<iter, iter> used more often to represent a range? 
I suspect that the reasoning runs like this:

(1) Users of containers will sometimes want just the begin() or end()
iterator, and we don't want to ask them to pay the cost of obtaining
and returning both if they only want one.  So containers *must*
implement begin() and end().

(2) Users might sometimes want the complete contents of a container as
a range.  However, to add a range() member function, when we already
have begin() and end(), is a little redundant.  If users want an
iter-pair, they can just call std::make_pair(c.begin(), c.end())
(which is exactly what the library implementation of range() would
probably do).

(3) Algorithms operate on ranges, so perhaps they should take
iter-pairs.  However, to get an iter-pair from a container requires an
extra piece of work, either on the users part:

  std::copy(std::make_pair(v.begin(), v.end()), out_iter);

or on the library's part:

  std::pair<iterator, iterator> vector::range() { 
     return make_pair(this->begin(), this->end());
  }

with little obvious benefit.  So, never mind.

Would using ranges or iter-pairs be safer than working with individual
iterators?  In theory, yes, I suppose so.  In practice, however, I
don't know that this has become a real problem.  I can't remember
running into an "invalid iterator range" error personally.  But
others' experience may be different.

---
[ 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                       ]



