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)   
|