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,825 of 33,346   
   Jorgen Grahn to All   
   Re: iostream replacement   
   26 Jan 13 10:31:32   
   
   From: grahn+nntp@snipabacken.se   
      
   On Fri, 2013-01-25, fmatthew5876 wrote:   
      
   (Other attributions missing.)   
      
   >> > first example of operator overloading abuse.   
   >> Define abuse, please.   
   >   
   > An operator should only be overloaded if the new type somehow clearly   
   > represents a primitive type with similar operations. An example of good   
   > operator overloading is arithmetic operators for vectors and matrices in   
   > a math library or pointer operators for an iterator or smart pointer.   
      
   That was the reason operator overloading was added to the language, yes.   
   Using a new maths library would be unbearably ugly without it.   
      
   > << and >> are bit shift operators. I would only define them for a class where   
   > they were actually shifting bits, like std::bitset.   
   >   
   > The only reason we accept << and >> is because the standard library does it.   
   > If you looked at someone else's code base where they invented a new purpose   
   > for some operator you'd probably be very skeptical, I know I would.   
      
   You're assuming there's agreement among C++ programmers about that.   
   I don't think there is. And there's no support for that view in the   
   language itself; as you wrote iostreams does it already.   
      
   Personally, I wouldn't mind such code at all, if there was a good   
   reason (like in the maths library and iostreams examples) and the risk   
   of confusion was low (like in the iostreams case).   
      
   /Jorgen   
      
   --   
     // Jorgen Grahn    O  o   .   
      
      
         [ 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