Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 33,268 of 33,346    |
|    K. Frank to All    |
|    Why aren't "tri-valent" comparison funct    |
|    31 Dec 13 23:13:06    |
      From: kfrank29.c@googlemail.com              Hello Group!              The venerable qsort takes a takes a comparison function       that returns an integer less than, equal to, and greater       than zero for x < y, x == y, and x > y, respectively (where       x and y are the arguments of the comparison function).              But the standard library is based on boolean comparison       functions that are true for x < y, and false otherwise.              It seems to me that this introduces a modest inefficiency       when testing for equality, as you have to call the comparison       function twice, i.e., x == y if lessThan (x, y) and       lessThan (y, x) are both false.              Lots of times, e.g., for a multi-field struct, the cost of       executing (and the work of writing) a trivalent <, ==, >       comparison function is essentially the same as a that of       a typical lessThan function. So why does the standard       library not support both versions, and instead give up       the potential benefit of the trivalent comparison?                     Thanks for any wisdom.                     K. Frank                     --        [ See http://www.gotw.ca/resources/clcm.htm for info about ]        [ comp.lang.c++.moderated. First time posters: Do this! ]              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca