…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.
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.
…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.
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.