This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Implementing normal algorithms using predicate versions


chris <caj@cs.york.ac.uk> writes:

| Paolo Carlini wrote:
| 
| > 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?!?
| >
| I was intending on using something like (warning: away from C++
| compiler, I haven't even compiled this code!)
| 
| template<typename __T1, typename __T2>
| struct __default_predicate {
| bool
| operator()(const __T1& __t1, const __T2& __t2) { return __t1<__t2;}
| };

YEs, that is right.  And in fact, this is the technique used in our
valarray implementation.  See bits/valarray_before.h for instance.

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]