This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Implementing normal algorithms using predicate versions
Nathan Myers wrote:
On Sun, Nov 28, 2004 at 03:00:31PM +0000, caj wrote:
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...
This is probably just historical. When the STL was written, compoilers
just weren't very good. Anywhere you can demonstrate that it actually
does produce the same code, nowadays, I think a patch would be welcome.
Interesting... In fact this issue is more general: should the library be
"optimized"
for -O2 or for -O0? Are we ready to trade some loss of performance at low
optimization levels for the sake of header simplicity (or other ends)?!?
To be clear,
in the specific case at issue I would say yes (in principle) ;)
Anyway, more to the point, I don't see clearly how you would *actually*
implement the proposal. In my reading of the standard (17.4.3.1/1) an user
of the library can definitely provide his own specialization of less<>,
therefore,
the trivial idea (i.e., calling the predicated version with less) seems
a "no-no"...
Chris, Nathan, do you have already something more specific in mind or maybe
my point above is wrong?!?
Paolo.