From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.ada Subject: Re: Top 10 Worst C# Features Date: Wed, 14 Oct 2015 15:26:21 +0100 Organization: A noiseless patient Spider Message-ID: <87mvvla5ma.fsf@bsb.me.uk> References: <5cb5c989-4d12-41d8-88df-ab45988ba8a1@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="3504"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/nVnR7QDZaJlBI9dTfKRmPZOFV6qrEth4=" Cancel-Lock: sha1:MqLxma6hDQDgQAzn4DcqEkTpWLk= sha1:mEr3wCjATaSN3M7utVc3imRUCVM= X-BSB-Auth: 1.18f2c8ec1a4076e61670.20151014152621BST.87mvvla5ma.fsf@bsb.me.uk Xref: news.eternal-september.org comp.lang.ada:27972 Date: 2015-10-14T15:26:21+01:00 List-Id: Maciej Sobczak writes: > Yes, we understand that it is possible to have incompatible > implementations of operator== and operator!= in C++ (assuming that > this is the language you are referring to), but we are willing to take > this risk (and address it by other means) as it allows us to implement > these operators more efficiently. Do you mean that there are reasons to permit !(a == b) and a != b to have different values in some cases? I don't think you mean this (because your example does not obviously address that possibility), but I am not 100% sure. > One possible example where this could be possible is when the > encapsulated data has a digital signature or some other short digest > available with the property that when two digests are different then > the objects are surely different (and this can be determined very > quickly), whereas when the digests are equal then more work is needed > to determine whether the objects are equal, too. In this case, our > operator!= can be much faster than operator== and we are willing to > benefit from the optimization opportunity here. This could not be > possible if one is automatically derived from the other. I don't see why bool operator!=(const T &other) const noexcept { if (this.hash != other.hash) return true; return !this.long_slow_equality_test(other); } is any more or less efficient than bool operator==(const T &other) const noexcept { if (this.hash != other.hash) return false; return this.long_slow_equality_test(other); } but I may have missed the point you are trying to make. -- Ben.