RepugNaNt [entries|reading|network|archive]
simont

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

Wed 2011-12-07 15:45
RepugNaNt
LinkReply
[identity profile] deliberateblank.livejournal.comWed 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.
Link Reply to this | Parent | Thread
[personal profile] gerald_duckThu 2011-12-08 11:31
This is another case in point for my claim up there that the STL should offer ranges instead of — or at least as well as — iterators.

Given range support, especially if containers themselves presented the range concept, the algorithms that currently accept a pair of iterators would all accept a range and your std::count_if example would work out of the box.

Now that C++11 is out there, I'm seriously considering putting some concrete proposals in for the next revision of C++, including ranges.
Link Reply to this | Parent
navigation
[ go | Previous Entry | Next Entry ]
[ add | to Memories ]