🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

insert for map and multimap

#1733
From: Ajay Kamdar
Date: Thu, 17 Aug 1995 18:40
35 lines
1705 bytes
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.

FYI, ObjectSpace's STL<ToolKit> provides, as an extension, an insert
member function with this signature. But I would much prefer to write
code which can be ported to different STL implementations.

So I wonder why the DWP itself doesn't make calling insert easier and the
code possibly more efficient? Could someone help me understand?

I would have settled for
    m.insert(make_pair(3, 5.0));

But that doesn't work either because there is no conversion from
pair<T1,T2> to pair<const T1,T2>.


-- 
Ajay Kamdar        |    Email: ajay@lehman.com    |    Standard Disclaimer 
Lehman Brothers    |    Phone: (201) 524-5048     |


---
[ 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: <9508170857.ZM22058@jabba>
Path: arc1-ca.pugleaf.net!news.mindlink.net!agate!agate!Matt

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.mindlink.net!agate!agate!Matt
From: ajay@lehman.com (Ajay Kamdar)
Newsgroups: comp.std.c++
Subject: insert for map and multimap
Date: 17 Aug 1995 18:40:01 GMT
Organization: <none>
Approved: Matt@physics.berkeley.edu
Message-ID: <9508170857.ZM22058@jabba>
NNTP-Posting-Host: austern.hip.berkeley.edu