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 33,208 of 33,346   
   DeMarcus to All   
   Re: Will value semantics make C++ die?   
   15 Sep 13 23:10:49   
   
   From: demarcus_at_hotmail_com@tellus.orb.dotsrc.org   
      
   >> Here is where I don't understand how to perceive   
   >> std::optional. Is it a Value or Pointer?   
   >   
   > I'm not really familliar with your terminology (*), but if I'm not   
   > mistaken, it's a value if T is a value, it's a pointer if T is a   
   > pointer, in other words optional doesn't add a level of indirection   
   > to those T already provide.   
      
   It might have been the intention to not add a level of indirection but   
   the syntax says differently since you must use Pointer syntax   
   (operator* and operator->) to get the Value.   
      
   struct A   
   {   
        void fnc();   
   };   
      
   optional intAsT = 3;   
   int i = intAsT; // ERROR!   
      
   optional AasT;   
   AasT.fnc(); // ERROR!   
      
   optional intPtrAsT;   
   *intPtrAsT = 10; // ERROR!   
      
   optional APtrAsT;   
   APtrAsT->fnc(); // ERROR!   
      
      
   I would love to see optional as a Value, but until we have language   
   support for it so we can get rid of the Pointer syntax, I'd rather see   
   it as a generic pointer with one level of indirection. Mixing zero   
   level and one level of indirection in the interface is paving for   
   confusion and bugs.   
      
   The new confusion, if we would make std::optional a kind of smart   
   pointer would be that we may think that it allocates on the heap and   
   has shallow copy. However, I think that's easier to keep track of in   
   the head than a mixed interface.   
      
   I guess it's just me since std::optional is already approved for the   
   standard. But for the future I think it would be good to investigate   
   how we can provide Value syntax to smart objects, similar to how   
   normal references T& provide Value syntax to pointers.   
      
      
   Regards,   
   Daniel   
      
      
      
   --   
         [ 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