220 35931 <acd594ce-5289-44de-b760-19e655d84a7b@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: adrian.hawryluk@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: operator[](...)
Date: Sat, 16 Dec 2017 08:40:41 -0800 (PST)
Lines: 152
Approved: news@gmane.org
Message-ID: <acd594ce-5289-44de-b760-19e655d84a7b@isocpp.org>
References: <ea8aec36-305c-48ca-aedc-0db120fd8fcc@isocpp.org>
 <8bbeac1f-f698-4e49-9e1f-4cb1ab389b09@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_2718_137562556.1513442441864"
X-Trace: blaine.gmane.org 1513442445 10721 195.159.176.226 (16 Dec 2017 16:40:45 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sat, 16 Dec 2017 16:40:45 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCULLOGNUQIRBCUZ2XIQKGQE4NWCXSQ@isocpp.org Sat Dec 16 17:40:39 2017
Return-path: <std-proposals+bncBCULLOGNUQIRBCUZ2XIQKGQE4NWCXSQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-vk0-f71.google.com ([209.85.213.71])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCULLOGNUQIRBCUZ2XIQKGQE4NWCXSQ@isocpp.org>)
	id 1eQFVs-0002Bv-V2
	for gclcip-std-proposals@m.gmane.org; Sat, 16 Dec 2017 17:40:37 +0100
Original-Received: by mail-vk0-f71.google.com with SMTP id o84sf3930236vka.7
        for <gclcip-std-proposals@m.gmane.org>; Sat, 16 Dec 2017 08:40:44 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=wSnNo7Y/5gt6C52nykSNhgKkAXHcE57RtOl+7xs8y2c=;
        b=a3q/0ckZxR2k7i50PRdy4bAP9+JP4VdSvPhCQ24fRyQb0jCGUTV01YFqInr3WY0ybh
         /ZLZDYVJ4k9xdjLLGndFntAa3wvagsHNEx6yJ90KjWGNwhSq6K4ES15jCRf6EbVlSFq2
         UdIval02jP9AurRmz3+faQIPVa8SAkwE0zKq+QGYqySu4hFk9TRmKeqU0SDu17pVdJkD
         99c/XGiOtn+YtO+tvqrGZsaBs50CFcS1md/rTvixYNGC3XQuT06Vx5zBfZp4uPih75k2
         AODWcgTUh81byd7TmxBaDKoyan9eh6j2CXowXEIFnTzCx+U5wLc2eH0SSCNViwP+J44W
         9wAw==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=wSnNo7Y/5gt6C52nykSNhgKkAXHcE57RtOl+7xs8y2c=;
        b=cBskI9qpItCthP/k0D/QOZXEn0yoH3X0b1CD7pT4ui1tfIU8ISGbtzACAQeckQMJ+O
         rSB06r2Qmgqj4UwpHlElejpq7KA+JZ0+9jmW5LcgalLDm8AvC3ejOaLJEf6CeZgSK4qM
         I8yeoIk+k6HJ/2fCtBC7v6EvZhQC5UdxOnt+mZXBbX9pAbndWQ6BPPNu6MJESa+CgA4Q
         AXGoxJ4jLzHhv4Uyi8V5hYTUhL4BuyWt4CwDkU04wv4hKw/+xDe78IHWKu6MHOSrZ9kr
         tuPo1iVERiupkC8l5r83icyCYoAsm27yO5bHoalpbHVnmyTLvHSJ9XKNLc8lDQmnlxP3
         jK4g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:x-original-sender:reply-to:precedence
         :mailing-list:list-id:x-spam-checked-in-group:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=wSnNo7Y/5gt6C52nykSNhgKkAXHcE57RtOl+7xs8y2c=;
        b=bTTq2gxmyscHVg22L8z6eegHTBEZ0EU4sAvl1y2ym7CS8oXtaIXCBUnwdixwjrYK4D
         7IZKMR5Zruy/nb7Z68VaXKmkFIB0ggPwuZLCbdc0GWU1pCjkBceNLhReWJg+xhMETcDf
         GKVjCufLrBV/srLjk3K/wPgpygrQ512+eR9sc0CCskHeGELcT843Pi029S8vIvZUtJUH
         klC+hsVOExQxyvPNk/AAuVsP+NC3emcDv19g44GPQBv95LuzH1hE62Zd2PdwaPRAxQt4
         pv8qk35yN3+zkIFRbJYytsEE75mrM1dedtik3kwmZA7rlrJNmO2i/c4E05RoavJJdWN1
         V2dA==
X-Gm-Message-State: AKGB3mK80iju40tOw2xs9C0ASBdCMcSBUkFkF74HY77T2ex/u0sgHwFS
	g0vJsIDN2LUJuz2/PRoaejIT2A==
X-Google-Smtp-Source: ACJfBosnBuS6HV/iYvjKIdDS2bMUt40Mr7hzE8S9etiTf1TF/ZZk1/Aap0kLyzpUXsqbMaSDVIp+OQ==
X-Received: by 10.31.189.209 with SMTP id n200mr6289160vkf.70.1513442444136;
        Sat, 16 Dec 2017 08:40:44 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.176.86.25 with SMTP id y25ls3530407uaa.10.gmail; Sat, 16 Dec
 2017 08:40:42 -0800 (PST)
X-Received: by 10.31.178.196 with SMTP id b187mr1775960vkf.8.1513442442438;
        Sat, 16 Dec 2017 08:40:42 -0800 (PST)
In-Reply-To: <8bbeac1f-f698-4e49-9e1f-4cb1ab389b09@isocpp.org>
X-Original-Sender: adrian.hawryluk@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:35931
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/35931>

------=_Part_2718_137562556.1513442441864
Content-Type: multipart/alternative; 
	boundary="----=_Part_2719_1905859367.1513442441864"

------=_Part_2719_1905859367.1513442441864
Content-Type: text/plain; charset="UTF-8"



On Saturday, November 25, 2017 at 4:11:21 PM UTC-5, Nicol Bolas wrote:
>
> On Saturday, November 25, 2017 at 2:08:25 PM UTC-5, Ryan Nicholl wrote:
>>
>>
>> My suggestion is to allow overloading operator [] with multiple 
>> arguments, e.g.:
>>
>> class image
>> {
>>   ...
>> public:
>>   ...
>>
>>   pixel & operator[](size_t x, size_t y)
>>   {
>>     return internal_data[x+y*width];
>>   }
>> };
>>
>> /// used like:
>>
>> image my_image = ...;
>> ...
>> pixel px = my_image[5, 3];
>>
>> Would be most useful where I see 
>> [{...}]
>>
>> currently. E.g.:
>> output[{x,y}] = value;
>> when processing images.
>>
>>
> You've essentially undermined your proposal by highlighting a problem with 
> most multi-argument `[]` proposals.
>
> As it currently stands `output[x, y]` already has a meaning. Namely, it's 
> equivalent to `output[y]`; the entire text between the `[]` is taken as a 
> single expression, rather than a list of arguments.
>
> So you have to invent a new syntax to make what you want possible. Namely, 
> `output[{x, y}]`.
>

Why would anyone currently want to use a comma separated list inside of a 
`[]` is beyond me.  It is confusing and could be misconstrued as a 
multidimensional array index by newer users to the language.  Yes, there is 
a work around, but this is a workaround to something that shouldn't need to 
be worked around as it makes it more difficult to use and understand the 
language.

-- 
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 email 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/acd594ce-5289-44de-b760-19e655d84a7b%40isocpp.org.

------=_Part_2719_1905859367.1513442441864
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Saturday, November 25, 2017 at 4:11:21 PM UTC-5=
, Nicol Bolas wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;ma=
rgin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr">On Saturday, November 25, 2017 at 2:08:25 PM UTC-5, Ryan Nicholl w=
rote:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;=
border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><br>My sugges=
tion is to allow overloading operator [] with multiple arguments, e.g.:<br>=
<br><div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,18=
7,187);border-style:solid;border-width:1px"><code><div><span style=3D"color=
:#008">class</span><span style=3D"color:#000"> image<br></span><span style=
=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 </span><span =
style=3D"color:#660">...</span><span style=3D"color:#000"><br></span><span =
style=3D"color:#008">public</span><span style=3D"color:#660">:</span><span =
style=3D"color:#000"><br>=C2=A0 </span><span style=3D"color:#660">...</span=
><span style=3D"color:#000"><br><br>=C2=A0 pixel </span><span style=3D"colo=
r:#660">&amp;</span><span style=3D"color:#000"> </span><span style=3D"color=
:#008">operator</span><span style=3D"color:#660">[](</span><span style=3D"c=
olor:#000">size_t x</span><span style=3D"color:#660">,</span><span style=3D=
"color:#000"> size_t y</span><span style=3D"color:#660">)</span><span style=
=3D"color:#000"><br>=C2=A0 </span><span style=3D"color:#660">{</span><span =
style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">re=
turn</span><span style=3D"color:#000"> internal_data</span><span style=3D"c=
olor:#660">[</span><span style=3D"color:#000">x</span><span style=3D"color:=
#660">+</span><span style=3D"color:#000">y</span><span style=3D"color:#660"=
>*</span><span style=3D"color:#000">width</span><span style=3D"color:#660">=
];</span><span style=3D"color:#000"><br>=C2=A0 </span><span style=3D"color:=
#660">}</span><span style=3D"color:#000"><br></span><span style=3D"color:#6=
60">};</span><span style=3D"color:#000"><br><br></span><span style=3D"color=
:#800">/// used like:</span><span style=3D"color:#000"><br><br>image my_ima=
ge </span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> =
</span><span style=3D"color:#660">...;</span><span style=3D"color:#000"><br=
></span><span style=3D"color:#660">...</span><span style=3D"color:#000"><br=
>pixel px </span><span style=3D"color:#660">=3D</span><span style=3D"color:=
#000"> my_image</span><span style=3D"color:#660">[</span><span style=3D"col=
or:#066">5</span><span style=3D"color:#660">,</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#066">3</span><span style=3D"color:#660">]=
;</span><span style=3D"color:#000"><br></span></div></code></div><br>Would =
be most useful where I see <div style=3D"background-color:rgb(250,250,250);=
border-color:rgb(187,187,187);border-style:solid;border-width:1px"><code><d=
iv><span style=3D"color:#660">[{...}]</span></div></code></div><br> current=
ly. E.g.:<br><div style=3D"background-color:rgb(250,250,250);border-color:r=
gb(187,187,187);border-style:solid;border-width:1px"><code><div><span style=
=3D"color:#000">output</span><span style=3D"color:#660">[{</span><span styl=
e=3D"color:#000">x</span><span style=3D"color:#660">,</span><span style=3D"=
color:#000">y</span><span style=3D"color:#660">}]</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#660">=3D</span><span style=3D"color:#=
000"> value</span><span style=3D"color:#660">;</span><span style=3D"color:#=
000"><br></span></div></code></div>when processing images.<br><br></div></b=
lockquote><br>You&#39;ve essentially undermined your proposal by highlighti=
ng a problem with most multi-argument `[]` proposals.<br><br>As it currentl=
y stands `output[x, y]` already has a meaning. Namely, it&#39;s equivalent =
to `output[y]`; the entire text between the `[]` is taken as a single expre=
ssion, rather than a list of arguments.<br><br>So you have to invent a new =
syntax to make what you want possible. Namely, `output[{x, y}]`.<br></div><=
/blockquote><div><br></div><div>Why would anyone currently want to use a co=
mma separated list inside of a `[]` is beyond me.=C2=A0 It is confusing and=
 could be misconstrued as a multidimensional array index by newer users to =
the language.=C2=A0 Yes, there is a work around, but this is a workaround t=
o something that shouldn&#39;t need to be worked around as it makes it more=
 difficult to use and understand the language.<br></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/acd594ce-5289-44de-b760-19e655d84a7b%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/acd594ce-5289-44de-b760-19e655d84a7b=
%40isocpp.org</a>.<br />

------=_Part_2719_1905859367.1513442441864--

------=_Part_2718_137562556.1513442441864--

.
