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 31,721 of 33,346    |
|    Seungbeom Kim to All    |
|    Re: Specializing std::less without an op    |
|    07 Dec 11 11:21:05    |
   
   From: musiphil@bawi.org   
      
   On 2011-12-06 12:00, Nevin ":-]" Liber wrote:   
   >   
   > The compromise I use for these situations is to define operator< but not   
   > > , <= or >=.   
   >   
   > The problem is composibility. If you go down the path of std::less   
   > instead of operator<, and you want to use that type as a member of   
   > another class that you wish to be able to use as a key in a set or a   
   > map, you have to define a std::less for your new class (after all, if   
   > the actual ordering for your original type is meaningless, any ordering   
   > based on it is also meaningless). It gets very clunky very quickly.   
      
   Even if you use define operator< for T, which is a member of class S,   
   op< for S doesn't automatically get composed out of op< for T, but you   
   have to manually write op< for S using op< for T, just as with   
      
    struct complex { int re, im; };   
      
   op< for complex doesn't automatically get composed but you have to write   
      
    bool operator<(complex a, complex b) { /* ... */ }   
      
   So the difference between defining operator< and defining std::less   
   is negligible in this regard. Either way, you have to write a composite   
   comparator function using the comparator functions of its members.   
      
   --   
   Seungbeom Kim   
      
      
    [ 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