From -4431571285728516705
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,de3d1a33294b366f,start
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1995-03-27 22:49:51 PST
Path: nntp.gmd.de!Germany.EU.net!EU.net!howland.reston.ans.net!news.cac.psu.edu!news.pop.psu.edu!hudson.lm.com!godot.cc.duq.edu!news.duke.edu!news.mathworks.com!news.kei.com!simtel!news1.oakland.edu!newshub.gmr.com!hobbes.tad.eds.com!maverick.tad.eds.com!news-admin@tad.eds.com
From: jrd@tad.eds.com (Jay Dunning)
Newsgroups: comp.std.c++
Subject: STL: A few more operations needed
Date: 27 Mar 1995 15:58:25 GMT
Organization: EDS
Lines: 48
Distribution: world
Message-ID: <JRD.95Mar27095825@artemis.tad.eds.com>
Reply-To: jrd@tad.eds.com
NNTP-Posting-Host: artemis.c3e.pln.ses.cio.eds.com

In a comparison of STL with the Smalltalk 80 collection classes, STL
seemed to be missing the following:

for_each_if(first, last, func, pred)

	Applies func to each element in the range [first, last) for 
	which pred(*i) == true.  (This is comparable to the Smalltalk
	select method.)

multiset::insert(x, n)

	Inserts n copies of x.  (For compatibility with
	sequences and ST80 Bag class.)

{multi}map::find_value(first, last, value)

	Returns the first iterator i in the range [first, last) for
	which (*i).second == value.

const {multi}map::operator[](key) const

	Returns a reference to the value associated with key, without
	inserting a new element if key is not found.  This would 
	probably have to return a null reference for a not-found 
	condition, which may be politically incorrect, but I find
	the current behavior of operator[] counter-intuitive.  Besides,
	not having a const operator[] violates one of Scott Meyers' rules.

It would be useful to have iterator adaptors that could extract just 
the key or just the value from a {multi}map.

It might also be useful to support relational composition (like Smalltalk
MappedCollection):
	template <class MappedContainer1, class MappedContainer2>
	class composed_map {
          public:
            composed_map(MappedContainer1& mapa, MappedContainer2& mapb);
            reference operator[](const key_type& x)
                { return mapb[mapa[x]]; }
        };
(I would have preferred to show a non-template class inheriting from a base
class also common to map and multimap.)

Also, it seems to me that remove_copy() would be more appropriately called
copy_if(), since it does not actually remove elements (as does remove()), 
and it takes a predicate. This would require the behavior to be changed
from copying elements that fail the predicate to copying elements that
satisfy the predicate.


