Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c++ Subject: Re: We have a new standard! Date: Thu, 02 Jan 2025 13:58:34 -0800 Organization: None to speak of Lines: 59 Message-ID: <87pll4sws5.fsf@nosuchdomain.example.com> References: <20250101182527.00004b2f@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Thu, 02 Jan 2025 22:58:35 +0100 (CET) Injection-Info: dont-email.me; posting-host="a6ca1a2a8a1a56868adae0581a86a375"; logging-data="3697068"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18UFEvbcdxNIXNDwt3357xy" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:6N2Y6RkEFtDbYQGJ1TFDC6FmN0k= sha1:pvH3m5wwmQovHMACuO9Rh5Lau/U= Muttley@DastardlyHQ.org writes: > On Thu, 2 Jan 2025 17:54:18 +0100 > David Brown wibbled: >>On 02/01/2025 15:07, Muttley@DastardlyHQ.org wrote: >>> Overloading << and >> was unnecessary and confusing. >> >>Disagreed. I really don't think it was problematic. Nor did any of the >>/many/ people who were involved in the design of C++. Remember, the >>language and library has always been discussed, prototyped, and tested >>by lots of people before being released. Stroustrup was the main >>language designer, but he was far from alone. > > Committees often don't come up with optimal solutions. Using the same operator > for 2 entirely different operations unrelated in either concept or function > when there was no need to was illogical and perverse. Like "*" for multiplication and pointer dereferencing? Like "&" for bitwise "and" and address-of? Like "-" for negation and subtraction? >>The meaning of "cout << 0xFF << 2 << 1234;" is obviously a chain of >>outputs - output 0xff, output 2, output 1234. Regardless of the > > I would expect all mathematical operations to work in EXACTLY the same way > in an output stream. I would expect << and >> to have their usual precedence whether overloaded or not. > Eg I expect the output to be 256 here: > > std::cout << 255 + 1 << std::endl; Which it is. > Yet here there is no maths involved: > > std::cout << 255 << 1 << std::endl; > > Thats perverse. Apparently your expectation was incorrect. I understand that the precedence of "<<" and ">>" can be slightly confusing when they're used for I/O -- but it's fairly rare for operators with lower precedence than the shift operators to be used in I/O. Sure, you can write: std::cout << n = 42 << "\n"; and it won't compile, but parentheses are an easy fix and a good idea anyway. How often has it really been a problem for you? [...] -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */