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,505 of 33,346   
   Martin B. to Howard Hinnant   
   Re: Will a const object be moved on retu   
   30 Sep 11 01:04:08   
   
   0c387f35   
   From: 0xCDCDCDCD@gmx.at   
      
   On 30.09.2011 01:41, Howard Hinnant wrote:   
   > On Sep 29, 2:02 pm, "Martin B."<0xCDCDC...@gmx.at>  wrote:   
   >> Isn't this something that could be improved in a future version of the   
   >> standard? C++ already considers a local l-value as an r-value on return,   
   >> wouldn't it make sense to "ignore" the constness? After all, the object   
   >> *is* gonna be destructed right away, and for it's dtor, the constness is   
   >> irrelevant (or so I like to think).   
   >   
   > I think moving from const, even from within a function-local, will   
   > lead to more complicated, more confusion, than is worth the benefit.   
   > Right now the rules are sufficiently simple that almost all cases just   
   > work.  The returned-from local is typically not const.  And if it is,   
   > just make it non-const and you're good to go.  The benefit of moving   
   > from const is low, the cost (in teachability, language complexity) is   
   > not.   
   >   
      
   I think I beg to differ.   
      
   *Not* allowing const move return leads to a more complex teaching   
   experience.   
      
   In C++03 we have this situation:   
   (a/03) Make locals const if it makes sense : helps correctness   
   (b/03) Be *somewhat* wary of return-by-value. It may copy and be expensive.   
      
   In C++11 we have now this:   
   (a/11) Make locals const if it makes sense, *except* when you want to   
   return them   
   (b/11) return-by-value of locals is fine (for well written classes),   
   *but be wary*, the returned object must not be a const, otherwise you   
   may see copying which *can* be expensive.   
      
   If the Great Committee could come with a sane solution - C++(++):   
   (a/++) Make locals const if it makes sense : helps correctness   
   (b/++) return-by-value of locals is fine (for well written classes)   
      
      
   >From a C++ usability POV, the third one seem the easiest.   
      
      
   cheers,   
   Martin   
      
   --   
   Stop Software Patents   
   http://petition.stopsoftwarepatents.eu/841006602158/   
   http://www.ffii.org/   
      
      
         [ 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