3 ms·
In C++'s defense in the one example you gave, you could have just done this and had the same amount of code: if (map.find(x) != map.end()) { }
by tolmasky 14y ago
In C++'s defense in the one example you gave, you could have just done this and had the same amount of code:
if (map.find(x) != map.end()) {
}
- scott_s 14y agoNo, because then I would need to find it again (eiter through the find() member function, or through operator[]) to get a reference to it. Without a reference, I can't process it.
- tolmasky 14y agoWhy? In your original example you said "process x". You can also "process x" in mine: if (map.find(x) != map.end()) { // do stuff with x } You don't need the iterator to do anything with x. And if you do need the iterator (to perhaps keep iterating or something?) then you would also need to do extra work in the JavaScript example.