home bbs files messages ]

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,723 of 33,346   
   =?ISO-8859-15?Q?Daniel_Kr=FCgler?= to All   
   Re: Specializing std::less without an op   
   07 Dec 11 14:39:11   
   
   From: daniel.kruegler@googlemail.com   
      
   Am 07.12.2011 20:20, schrieb Nevin ":-]" Liber:   
   > In article,   
   >  Daniel Krügler  wrote:   
   >   
   >>> Or, as boost::shared_ptr does, is it regarded as preferable to instead   
   >>> go ahead and define an operator<() that returns lhs.get()<   rhs.get()   
   >>> even though the result of the operator<   is in general meaningless?   
   >>   
   >> I don't think that boost_shared pointer (or std::shared_ptr) is a *bad*   
   >> example for providing operator<. The underlying pointer does provide it   
   >> and since a smart pointer mimics the built-in pointer to some degree,   
   >> this addition looks ok.   
   >   
   > I don't think (raw) pointers have a guaranteed total ordering.  See   
   > C++11 5.9 for more details.   
      
   This is true, but not much of a problem, because std::shared_ptr (as   
   std::unique_ptr) implement operator < in terms of less<> of the underlying   
   pointer:   
      
   template   
   bool operator<(const shared_ptr& a, const shared_ptr& b) noexcept;   
   2 Returns: less()(a.get(), b.get()), where V is the composite pointer type   
   (5.9) of T* and U*.   
      
   And the less<> specialization for pointers *does* induce a total order (see   
   20.8.5 p8).   
      
   boost::shared_ptr at least realizes a strict weak ordering, which also is   
   useful in general.   
      
   Greetings from Bremen,   
      
   Daniel Krügler   
      
      
      
   --   
         [ 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