220 28310 <nrru5o$sa6$1@blaine.gmane.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Matthew Woehlke <mwoehlke.floss@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Something is better then nothing: Please, relax
 Initializer List use with operators!
Date: Tue, 20 Sep 2016 14:12:09 -0400
Lines: 97
Approved: news@gmane.org
Message-ID: <nrru5o$sa6$1@blaine.gmane.org>
References: <0892f743-bca2-4f18-b023-d4a57cea60fb@isocpp.org>
 <0e27bc76-eada-4d70-80d7-b91b5a2d5767@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Trace: blaine.gmane.org 1474474014 18051 195.159.176.226 (21 Sep 2016 16:06:54 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Wed, 21 Sep 2016 16:06:54 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101
 Thunderbird/38.1.0
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBC37LBFWUIFBB567RK7QKGQE7T2QVBQ@isocpp.org Wed Sep 21 18:06:50 2016
Return-path: <std-proposals+bncBC37LBFWUIFBB567RK7QKGQE7T2QVBQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-io0-f198.google.com ([209.85.223.198])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBC37LBFWUIFBB567RK7QKGQE7T2QVBQ@isocpp.org>)
	id 1bmk2a-0002T9-WB
	for gclcip-std-proposals@m.gmane.org; Wed, 21 Sep 2016 18:06:33 +0200
Original-Received: by mail-io0-f198.google.com with SMTP id g22sf152746740ioj.1
        for <gclcip-std-proposals@m.gmane.org>; Wed, 21 Sep 2016 09:06:34 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=to:from:subject:date:lines:message-id:references:mime-version
         :content-transfer-encoding:user-agent:in-reply-to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=XJDHLykeU+nZnBul8dDeiCHQgekRoOXrPCEWHCOOqdw=;
        b=wfitEntwFVWEHRmnBYVVaDhpSUV9jorf9+pv75hv84p66sOZzZndFNyXABdFbRw5hJ
         +1LMDSxImA14OdzUxy4SJA3hiR9oCIHExXMRqjOwFqAV+L3HfDIeiH+mojVk02yA6I3L
         sIfK7iSjxY9abQcbJYWBF9L1EvWZLBwT+GmXzQAzWy0eNRHcXft2ScZNKQAOoYIeTVia
         YB5i+K6OUrdSJVttPqNXJ2IkOZ4rtM2jo2HDQBTtp7hwuIROSUcukFfDLZGCte6GTX8w
         bJebFeF+S0mJ+2W6YD/yPY/f4sxHpcb3GmaxwYM2mpK2Jl+HzMa7uU6MzqFU2RBUGGcn
         MPFQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:to:from:subject:date:lines:message-id:references
         :mime-version:content-transfer-encoding:user-agent:in-reply-to
         :x-original-sender:x-original-authentication-results:reply-to
         :precedence:mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=XJDHLykeU+nZnBul8dDeiCHQgekRoOXrPCEWHCOOqdw=;
        b=PXYveUGUXCa9uULExNgDoNwviOo2KQLZiXkAQWlYaL2ygHnAL5+dJmtGgbs64dni9M
         +tKQICVJufyYNlgTWarStFwd7EmKlXU1T1SL57rIvarPmOrt+2bSCof+pGIx/iv21hEK
         DwfYfptfD0ynI14MACh/RHILdbXB4NS0AcjSmcoAfeI7+loBJp/CkupoFp+eeYxkf2hb
         ay2HfJhwnMSdKAFnPf5CkfpxWAuIxTUt/f4brZunK3myPDpQ3BbLLkZQxwTIHswnJ8cv
         HuvyVU39UUxmzfJa04epZo/8ErDqH2PZvEDzGNRgKVruo5OZc7Zllv77NiXK+Cb2/GId
         QxTA==
X-Gm-Message-State: AE9vXwNi/+CtMu+/ztP4z6ptg780VEauGueALzRdJWK8anCtbug8UYHkizH7fdjeWYUpqA==
X-Received: by 10.157.27.240 with SMTP id v45mr3091284otv.106.1474473976017;
        Wed, 21 Sep 2016 09:06:16 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.157.30.131 with SMTP id n3ls4676746otn.39.gmail; Wed, 21 Sep
 2016 09:06:15 -0700 (PDT)
X-Received: by 10.157.45.202 with SMTP id g68mr2813352otb.112.1474473975180;
        Wed, 21 Sep 2016 09:06:15 -0700 (PDT)
Original-Received: by 10.55.165.136 with SMTP id o130msqke;
        Tue, 20 Sep 2016 11:12:30 -0700 (PDT)
X-Received: by 10.25.126.208 with SMTP id z199mr13884457lfc.7.1474395150242;
        Tue, 20 Sep 2016 11:12:30 -0700 (PDT)
Original-Received: from blaine.gmane.org ([195.159.176.226])
        by mx.google.com with ESMTPS id j8si13016524lfg.28.2016.09.20.11.12.30
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Tue, 20 Sep 2016 11:12:30 -0700 (PDT)
Received-SPF: neutral (google.com: 195.159.176.226 is neither permitted nor denied by best guess record for domain of gclcip-std-proposals@m.gmane.org) client-ip=195.159.176.226;
Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2)
	(envelope-from <gclcip-std-proposals@m.gmane.org>)
	id 1bmPWm-0000kX-Mm
	for std-proposals@isocpp.org; Tue, 20 Sep 2016 20:12:20 +0200
X-Injected-Via-Gmane: http://gmane.org/
Original-Lines: 82
Original-X-Complaints-To: usenet@blaine.gmane.org
X-Enigmail-Draft-Status: N1110
In-Reply-To: <0e27bc76-eada-4d70-80d7-b91b5a2d5767@isocpp.org>
X-Original-Sender: mwoehlke.floss@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=neutral
 (google.com: 195.159.176.226 is neither permitted nor denied by best guess
 record for domain of gclcip-std-proposals@m.gmane.org) smtp.mailfrom=gclcip-std-proposals@m.gmane.org;
       dmarc=fail (p=NONE dis=NONE) header.from=gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:28310
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/28310>

On 2016-09-18 09:08, Nicol Bolas wrote:
> On Sunday, September 18, 2016 at 8:41:39 AM UTC-4, mihailn...@gmail.com=
=20
> wrote:
>> Back to the example - it is hard to explain why this is working:
>> Point p;
>> p =3D {-1, -1};=20
>>
>> but this is not:
>>
>> if(p =3D=3D {-1, -1}) return;
>
> Because one is assignment while the other is equality testing. They're tw=
o=20
> different things.
>=20
> Why is that hard to explain?

....because it *doesn't make sense*. Consider:

  foo.operator@({...}) // works for any operator
  foo @ {...} // only works for '=3D'

....where `@` is replaced with a valid operator, e.g. `=3D=3D`, `*`, `+`,
etc. Why *should* it work with `=3D` but not other operators?

Consider also:

  A a;
  B b; // B is convertible to A

  a.operator@(b); // works
  a @ b; // works

Why do these mean the same *except* when `b` is replaced with an
initializer list *and* the operator is not `=3D`? That just feels like an
arbitrary rule that isn't otherwise consistent with the language.

>> *But this is actually relatively easy to explain why it's not working*:
>> if({-1, -1} =3D=3D p) return;
>
> Um, no. If we allow `X =3D=3D Y` to work, then it makes sense that we all=
ow `Y=20
> =3D=3D X` to work.

As Johannes already noted, your logic is faulty (non sequitor):

  // Let 'a' be a complex type with 'bool operator=3D=3D(bool) const'
  a =3D=3D true; // okay
  true =3D=3D a; // error

Operators =E2=80=94 even the comparison operator =E2=80=94 are not necessar=
ily
commutative. (Similarly, I could readily create some types for which `(a
=3D=3D b) !=3D (b =3D=3D a)`.)

I am *quite* happy to argue that `{...} =3D=3D expr` should not be allowed.
More accurately, it should be allowed iff there exists a conversion from
`expr` to std::initializer_list *and* there exists an operator=3D=3D for
std::initializer_list, just like if the LHS was any other type. (IOW,
since those conditions are false, it follows that the operation is not
permitted, *according to the same rules that apply to any other LHS
type*. This is therefore logical and consistent with the language as a
whole.)

> *Bonus:*
>> This must work, it really must work:
>> const auto e =3D car ? car->engine() : {};
>>  We know it does not but it should, no reason why not - first arg is=20
>> given, second arg is given, the the third must the same type as the seco=
nd,=20
>> so we have everything to deduce it!
>=20
> Again, that goes back to consistency. `!car ? {} : car->engine()` is=20
> conceptually the same, yet it wouldn't work under your scheme.

Why couldn't it? The compiler ought to be able to deduce what to do with
an initializer list as one half of a ternary, regardless of which half
it appears in.

The rule here is simple; if one "half" of a ternary is an initializer
list and the other is not, and there exists a conversion to the type of
the other "half" from an initializer list, then that conversion is
implicitly applied to the initializer list.

--=20
Matthew

--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/nrru5o%24sa6%241%40blaine.gmane.org.

.
