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 32,135 of 33,346   
   Christopher Creutzig to James K. Lowden   
   Re: in/out arguments   
   14 Apr 12 11:29:31   
   
   From: christopher@creutzig.de   
      
   On 4/14/12 7:35 AM, James K. Lowden wrote:   
      
   > I didn't cite code I usually see.  I specifically cited the STL   
   > because as far as I'm concerned that's the canonical example   
   > library.  And I didn't say it's never justified, only rarely.   
      
   I regard the following calls to have in/out parameters and to not be   
   exotic corner cases of STL:   
      
   std::cin << 1;   
      
   std::set s;   
   s.insert(1);   
      
   ++i;   
      
   > Dave Abrahams suggests that the this pointer in e.g. list::sort()   
   > can be thought of as an i/o parameter in some sense.  Down that road   
   > lies a long computer science debate that I didn't mean to engage.   
      
   But both semantically and from an optimization point of view, his   
   argument makes perfect sense. Pointer/reference is just an   
   implementation detail when it comes to “this,” and the syntactic sugar   
   of not having to provide this pointer/reference as an argument to the   
   function makes code more readable, but does not really change anything   
   beyond that.   
      
   > Please note, my basic point was that i/o parameters are rare enough,   
   > on the evidence, that they don't merit distinction in the language   
   > syntax.  I would guess parameters are declared 90% by value, 9%   
   > output, and 1% i/o.  That's what I meant by "rarely used".   
      
   Since I don't follow the way you are counting, it is not surprising   
   that my guesstimates are very different from yours. To me, modifying   
   operations take in/out parameters – the jury is still out on   
   assignment operators, but I believe those will be found guilty as   
   well. Not that there's anything wrong with having in/out parameters.   
      
   Actually, I'd see “output” parameters as a special case of in/out   
   parameters (which are denoted by non-const reference in C++) where the   
   input value is ignored – unless you can show me a valid way to have a   
   reference parameter which only gets constructed inside the function   
   called.   
      
      
   Christopher   
      
      
   --   
         [ 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