RepugNaNt [entries|reading|network|archive]
simont

[ userinfo | dreamwidth userinfo ]
[ archive | journal archive ]

Wed 2011-12-07 15:45
RepugNaNt
LinkReply
[personal profile] gerald_duckWed 2011-12-07 16:20
…except strictly it's probably i->second==value rather than *i==value, because dictionary will probably be an associative container.

…and you'd have to name the iterator's type explicitly before C++11.

…and in C++ you might be using an associative container that can map the same key to multiple values, in which case you'd need to know whether you wanted all entries with that key to have the specified value or at least one.
Link Reply to this | Parent | Thread
[identity profile] ptc24.livejournal.comWed 2011-12-07 16:39
http://www.python.org/dev/peps/pep-3106/ (http://www.python.org/dev/peps/pep-3106/) has "pseudo-code to define the semantics":

class d_items:

    def __init__(self, d):
        self.__d = d

    def __len__(self):
        return len(self.__d)

    def __contains__(self, (key, value)):
        return key in self.__d and self.__d[key] == value

    (etc.)


which suggests that that sort of optimisation (if you can really call it that) is what is in mind.
Link Reply to this | Parent
navigation
[ go | Previous Entry | Next Entry ]
[ add | to Memories ]