Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
Initializing a map...
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="James Kanze, post: 3452487"] Any ugliness would be hidden in map_initializer, so who cares. That's not really the issue---you're going to deep copy the map anyway, so a little more or less shouldn't matter. The issue is really one of semantics. Using insert or operator[] have different semantics in the case of duplicates, and in the case of insert, you can easily check the return value, and generate an error (exception or assertion failure) in case of duplicates, which is probably the most useful semantics. You could, but I don't see what that buys you. Insertion without the hint (or with the wrong hint) is O(ln n). With the hint, it is O(1), but lower_bound is O(ln n), so there's no point in using it just to provide a hint. Which could also be a very important advantage if one of the types didn't support default construction. All in all: forget about optimization---good design requires the use of insert. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
Initializing a map...
Top