Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 32,617 of 33,346    |
|    Seungbeom Kim to James Lothian    |
|    Re: The dangers of returning const refer    |
|    25 Oct 12 23:31:57    |
      From: musiphil@bawi.org              On 2012-10-25 17:59, James Lothian wrote:       > It's       > a shame that std::map<> doesn't provide (as far as I can tell)       > a member fn that gets given a value and inserts a new entry if       > there isn't one, or overwrites the value of one that's there       > already. Operator[] is close to what you want, but the fact       > that the new map entry can be created before you've had a       > chance to create the value you're going to put in it seems to       > make it unexpectedly hard to use exception-safely.              If you finish creating the value to be inserted (in a separate       statement) before trying to access the map, it's very close to       what you want:               // given std::map |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca