Implementing normal algorithms using predicate versions
Matt Austern
austern@apple.com
Mon Nov 29 18:01:00 GMT 2004
On Nov 28, 2004, at 7:00 AM, caj wrote:
> Hi!
>
> I apologise, as I'm sure this question has a simple answer, but I
> can't find it...
>
> Many algorithms have a predicated version, and a version which simply
> uses operator<. Why not implement the operator< versions using the
> predicated versions? This would seem to half the size of the algorithm
> heaader, remove lots of redundant code, and on -O2 seems to produce
> identical code...
It's a good idea, but we can't quite plug std::less into the predicate
version of the algorithms. There are a few corner cases where that
would do something different in a way the user could detect. I think
what we could and should do is write our own predicates that are
guaranteed to behave the same way as the version using bare operator<.
--Matt
More information about the Libstdc++
mailing list