🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1767

Re: insert for map and multimap

#1767
From: Klamer Schutte
Date: Fri, 18 Aug 1995 14:53
38 lines
1814 bytes
In <9508170857.ZM22058@jabba> ajay@lehman.com (Ajay Kamdar) writes:

:Given a multimap, this is what I would have *liked* to do:

:    multimap<int,double> m;
:    m.insert(3, 5.0);

:But of course, such a function does not exist. Is there a reason why
:STL opted not to provide this convenient interface and chose to go
:with the more tedious (for the user) approach of insert taking
:a pair<const T1,T2>? Besides being convenient, it is also possible
:that providing the key and the value separately rather than creating
:an intermediate pair is actually more efficient.

I also would like to see the insert member described above.

You of course can make a child class of multimap with the insert member
you want. Or you can use the function below:

template <class Key, class T, class Compare>
inline void
map_insert( multimap<Key,T,Compare > &m, const Key &k, const T &v )
{
m.insert( pair<const Key, T>(k, v) );
}

multimap<int,double,less<int> > m;

map_insert(m, 3, 5.0);

Klamer
--
Klamer Schutte	-- +31-15-786054 -- klamer@ph.tn.tudelft.nl
http://www.ph.tn.tudelft.nl/People/klamer/Klamer.html
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <411h8u$fi8@cyber.tn.tudelft.nl>
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
References: <9508170857.ZM22058@jabba>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
Date: 18 Aug 95 14:53:01 GMT
Approved: fjh@cs.mu.oz.au
Return-Path: <daemon@ncar.UCAR.EDU>
From: klamer@ph.tn.tudelft.nl (Klamer Schutte)
Newsgroups: comp.std.c++
Subject: Re: insert for map and multimap
X-Original-Date: 18 Aug 1995 07:59:26 GMT
Organization: Delft University of Technology
Message-ID: <411h8u$fi8@cyber.tn.tudelft.nl>
References: <9508170857.ZM22058@jabba>
X-Newsreader: NN version 6.5.0 (NOV)