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,837 of 33,346    |
|    Seungbeom Kim to All    |
|    Re: iostream replacement    |
|    28 Jan 13 23:27:47    |
   
   From: musiphil@bawi.org   
      
   On 2013-01-28 13:08, fmatthew5876 wrote:   
   >>> I think overloading the comma operator would be even more   
   >>> confusing. I'm not even sure why overloading this is allowed in   
   >>> the first place.   
   >>   
   >> I kinda disagree with this. When you write text, you use comma to   
   >> separate items in a list. It would be the same here:   
   >>   
   >> cout, 1, 2, x, y, endl;   
   >   
   > This is even less visually pleasing. At least with << and >> there   
   > is some notion that things are being pushed onto or off of the   
   > stream. This looks like some kind of half written function call.   
   >   
   >> It's even simple to explain to a beginner: cout outputs a   
   >> comma-separated list of values; it's not even technically very   
   >> wrong since comma has lowest precedence of all operators. The only   
   >> ugly thing is the first comma (after cout).   
   >   
   > In terms of human textual representation, commas may look nice. The   
   > problem is the comma has a very specific meaning in C++. Overloading   
   > the comma operator is something that has very subtle implications   
   > that I don't think we want to force on everyone trying to print   
   > hello world.   
      
   Yes, indeed. Specifically, the comma operator is used to combine   
   multiple expressions into one, like this:   
      
    while (std::cout << count << '\n', count-- > 0) { ... }   
      
   If you substitute the comma operator for stream operations, the   
   meaning is silently changed and it becomes very tricky to get the   
   original meaning:   
      
    while (std::cout, count, '\n', count-- > 0) { ... } // wrong   
      
    while ((std::cout, count, '\n'), count-- > 0) { ... } // still wrong   
      
    // You need a cast!   
    while ((void)(std::cout, count, '\n'), count-- > 0) { ... }   
      
   --   
   Seungbeom Kim   
      
      
    [ 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