2 ms·
Yes. "[]" would denote the operator for accessing element of collection associated with key/index k by [k] syntax. Similarly "[]=" would denote operator for st
by shoo 6y ago
Yes. "[]" would denote the operator for accessing element of collection associated with key/index k by [k] syntax. Similarly "[]=" would denote operator for storing element under a given key/index.
E.g. in python these would correspond to a custom type implementing https://docs.python.org/3/reference/datamodel.html#object.__getitem__ https://docs.python.org/3/reference/datamodel.html#object.__... & https://docs.python.org/3/reference/datamodel.html#object.__setitem__ https://docs.python.org/3/reference/datamodel.html#object.__...
- marcus_holmes 6y agoOK, yeah, I get it now. so if I defined my own map type (e.g. orderedmap[T] that kept things in the order they were added) then I'd need to write code for the [] operator to access an element, is that right? I guess I'm not really sure how that differs from declaring orderedmap(T) (as it is in the proposal). Why do I need to overload one and not the other?