TheoLogic Posted June 12, 2012 Share Posted June 12, 2012 It is stupid, it shouldn't add a value in when you're reading from it. They only did this because it has to return a pointer that can be gotten or set: a = map[2] map[2] = a So it's a result of a limitation of the C++ language, because none of this stuff was implemented when they originally designed the thing. Which is why we call C++ an octopus made by nailing extra legs to a dog. It is not stupid, and clearly defined in the standard: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf (23.4.4.3 map element access) T& operator[](key_type&& x); * Effects: If there is no key equivalent to x in the map, inserts value_type(std::move(x), T()) into the map. * Requires: mapped_type shall be DefaultConstructible. * Returns: A reference to the mapped_type corresponding to x in *this. * Complexity: logarithmic. 1 Quote Follow me Link to comment Share on other sites More sharing options...
Josh Posted June 12, 2012 Author Share Posted June 12, 2012 Thanks to the C++ guys for the tips. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.