deliberateblank.livejournal.com |
Wed 2011-12-07 20:07 |
In many cases the STL manages to look like it ought to make what you want to do short and elegant (if not always comprehensible to the untrained eye), but on deeper inspection either the standard or all implementations manage to make it just ever so slightly the wrong side of impossible. (If it didn't get so close, it wouldn't be so irritating.)
if (std::count_if(C.equal_range(key), value)>0) ...
Except that equal_range returns a std::pair of iterators and the <algorithm> functions and equivalent container methods only take individual iterators, so you have to at least calculate the range as a temporary.
if (C.count(C::value_type(key, value))>0) ...
Except that count() (or just find()!) are only defined on key_type, not value_type. |
|