From: dave@boostpro.com   
      
   on Fri Apr 13 2012, Jonathan Thornburg    
   wrote:   
      
   > "Alf P. Steinbach" suggested:   
   >> Ideally there should   
   >> be "in", "out" and "in-out" designators as in Ada   
   >   
   > James K. Lowden wrote:   
   >> We almost have that now, right?   
   >>   
   >> in: value or const reference   
   >> out: reference   
   >> in/out: reference   
   >>   
   >> The last doesn't deserve distinction. It's rarely used because it's   
   >> rarely justified.   
   >   
   > I have two objections to this last comment. The first is practical:   
   > I'm willing to take James Lowden's word that in/out arguments are rarely   
   > used in the code bases he usually sees, but I'm not at all convinced   
   > that that's true for all C++ code bases.   
      
   IMO it's wrong on its face. Every mutating member function uses an   
   in/out argument. I know, someone will object because "this" is a   
   pointer. PotAYto potAHto. It could just as easily have been a   
   reference, and many think it should have been.   
      
   I think it probably /is/ rare to have more than 1 in/out argument.   
   That's a good thing, since mutations are a source of complexity. But   
   there are notable exceptions, e.g. swap   
      
   > For example, in my experience the following sorts of code all make   
   > frequent use of in/out arguments:   
      
      
      
   > There's a pattern here: all of these computations involve in-place updates   
   > to some data which we don't want to copy   
   > [possible reasons might include   
   > * copying would be horribly slow   
   > * there's not enough memory in the machine to make the copy   
   > * lots of people hold (and need to keep accessing through)   
   > pointers to the data]   
   >   
   > Admittedly, it's really hard (maybe impossible?) to make such computations   
   > exception-safe.   
      
   Not at all. Always remember (and don't ever forget):   
      
    "exception safety" == basic_guarantee   
    "exception safety" != strong_guarantee   
      
   --Dave   
      
   --   
   Dave Abrahams   
   BoostPro Computing   
   http://www.boostpro.com   
      
      
    [ 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)   
|