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,490 of 33,346   
   Marc to Thiago Adams   
   Re: Cast from shared_ptr* to shared_p   
   25 Sep 11 17:24:53   
   
   8e07ac59   
   From: marc.glisse@gmail.com   
      
   Thiago Adams  wrote:   
      
   > If this is true, why not increase the performance creating a cast   
   > operator at the shared_ptr ?   
   >   
   > Something like:   
   >   
   > operator const shared_ptr& () const   
   > {   
   >     return *((shared_ptr*)(this));   
   > }   
   >   
   > operator shared_ptr& ()   
   > {   
   >     return *((shared_ptr*)(this));   
   > }   
   >   
   > then:   
   >   
   > void f(const shared& s) {}   
   > shared sp;   
   > f(sp);   
   >   
   > would be fast.   
      
   The non-const version seems unsafe, for the same reason that casts   
   from char** to const char** are forbidden (I haven't thought about it   
   long, but it looks like it allows reverse conversions that remove a   
   const).   
      
   I've been interested in something similar for pairs: be able to   
   implicitly and without copy (reinterpret_cast-like) use a pair as   
   a pair (or any variant with more consts at the end than we   
   started with), and I implemented it the same way. I already wasn't   
   sure it was legal, but at least the definition of std::pair is pretty   
   clear in the standard, whereas for something more advanced like   
   shared_ptr, it isn't completely out of the question that the library   
   might provide a different implementation for const/non-const types.   
      
      
   --   
         [ 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