4 ms·
I have to disagree with some of the "warts": operator[] adds a member to a map if it does not already exist The main theme of this article seems to be "C++ gi
by rgarcia 15y ago
I have to disagree with some of the "warts":
operator[] adds a member to a map if it does not already exist
The main theme of this article seems to be "C++ gives you too much flexibility," but this is a case where C++ is enforcing a default behavior and limiting your flexibility. In Python, for example, understanding code that queries for a key in a dictionary requires you to know some context about whether that dictionary has a default value for missing keys. For all the quibbling the OP does about operator overloading, I'd expect him to be grateful for the predictable nature of map's operator[].
local static initialization is not thread safe
This is just wrong: http://stackoverflow.com/questions/1270927/are-function-static-variables-thread-safe-in-gcc http://stackoverflow.com/questions/1270927/are-function-stat...
- comex 15y agoHuh? The standard behavior in Python is to throw an exception if the key does not exist.
- gcr 15y agoI think rgarcia was talking about defaultdict and friends, see http://docs.python.org/library/collections.html#collections.defaultdict http://docs.python.org/library/collections.html#collections.... Classes that implement __getitem__ can behave however they want when you use brackets on them. See http://docs.python.org/reference/datamodel.html#object.__getitem__ http://docs.python.org/reference/datamodel.html#object.__get...