Topic: Parenthesized type names - make west const more consistent


Author: Justin Bassett <jbassett271@gmail.com>
Date: Fri, 10 Aug 2018 22:33:27 -0700 (PDT)
Raw View
------=_Part_989_1230215300.1533965607146
Content-Type: multipart/alternative;
 boundary="----=_Part_990_1563421355.1533965607146"

------=_Part_990_1563421355.1533965607146
Content-Type: text/plain; charset="UTF-8"

We currently have two ways to mark a type as a const type: west const and
east const:

const int x = 0; // west const
int const x = 0; // east const

One of the arguments I've seen for east const is that it's more consistent.
If you want a const pointer to int, you have to use east const:

const int* x; // mutable pointer to const int
int * const x; // const pointer to mutable int

However, what if we could group the types with parentheses?

const (int *) x; // const pointer to mutable int

Is this idea completely flawed, or is there some merit in it?

The first thing that comes to my mind is that there might be some confusion
with function types, but is that enough to toss the idea? What if we used
some other delimiter for grouping?

--
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/0b5f9a72-02a7-4b38-a857-6fae5709677b%40isocpp.org.

------=_Part_990_1563421355.1533965607146
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">We currently have two ways to mark a type as a const type:=
 west const and east const:<div><br><div class=3D"prettyprint" style=3D"bac=
kground-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border=
-style: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"pr=
ettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=
=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">int</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> x </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #066;" class=3D"styled-by-prettify">0</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #800;" =
class=3D"styled-by-prettify">// west const</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">int</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">const</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> x </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #066;" class=3D"styled-by-prettify">0</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #800=
;" class=3D"styled-by-prettify">// east const</span></div></code></div><div=
><br></div><div>One of the arguments I&#39;ve seen for east const is that i=
t&#39;s more consistent. If you want a const pointer to int, you have to us=
e east const:<br></div></div><div><br></div><div><div class=3D"prettyprint"=
 style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187,=
 187); border-style: solid; border-width: 1px; word-wrap: break-word;"><cod=
e class=3D"prettyprint"><div class=3D"subprettyprint"><font color=3D"#66006=
6"><span style=3D"color: #008;" class=3D"styled-by-prettify">const</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">*</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> x</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #800;" class=3D"styled-by-pret=
tify">// mutable pointer to const int</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">int</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">*</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">const</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> x</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #800;=
" class=3D"styled-by-prettify">// const pointer to mutable int</span></font=
></div></code></div><br>However, what if we could group the types with pare=
ntheses?</div><div><br></div><div><div class=3D"prettyprint" style=3D"backg=
round-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-s=
tyle: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"pret=
typrint"><div class=3D"subprettyprint"><font color=3D"#000088"><span style=
=3D"color: #008;" class=3D"styled-by-prettify">const</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">int</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">*)</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 x</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span></font><s=
pan style=3D"color: #800;" class=3D"styled-by-prettify">// const pointer to=
 mutable int</span></div></code></div><br></div>Is this idea completely fla=
wed, or is there some merit in it?<div><br></div><div>The first thing that =
comes to my mind is that there might be some confusion with function types,=
 but is that enough to toss the idea? What if we used some other delimiter =
for grouping?</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/0b5f9a72-02a7-4b38-a857-6fae5709677b%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/0b5f9a72-02a7-4b38-a857-6fae5709677b=
%40isocpp.org</a>.<br />

------=_Part_990_1563421355.1533965607146--

------=_Part_989_1230215300.1533965607146--

.


Author: Bo Persson <bop@gmb.dk>
Date: Sat, 11 Aug 2018 11:50:03 +0200
Raw View
On 2018-08-11 07:33, Justin Bassett wrote:
> We currently have two ways to mark a type as a const type: west const
> and east const:
>
> |
> constintx =0;// west const
> intconstx =0;// east const
> |
>
> One of the arguments I've seen for east const is that it's more
> consistent. If you want a const pointer to int, you have to use east const:
>
> |
> constint*x;// mutable pointer to const int
> int*constx;// const pointer to mutable int
> |
>
> However, what if we could group the types with parentheses?
>
> |
> const(int*)x;// const pointer to mutable int
> |
>
> Is this idea completely flawed, or is there some merit in it?
>

Not using raw pointers would be one way to avoid the potential problem.  :-)

So making it easier to use raw pointers is perhaps not the highest
priority.


And when I have a constant pointer, it more often ends up as

const int* const

where this proposal doesn't help.


     Bo Persson

--
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/pkmbc9%24tqq%241%40blaine.gmane.org.

.


Author: florian.csdt@gmail.com
Date: Sat, 11 Aug 2018 03:29:21 -0700 (PDT)
Raw View
------=_Part_1129_129490481.1533983361799
Content-Type: multipart/alternative;
 boundary="----=_Part_1130_1176892375.1533983361799"

------=_Part_1130_1176892375.1533983361799
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable



Le samedi 11 ao=C3=BBt 2018 11:50:15 UTC+2, Bo Persson a =C3=A9crit :
>
> On 2018-08-11 07:33, Justin Bassett wrote:=20
> > We currently have two ways to mark a type as a const type: west const=
=20
> > and east const:=20
> >=20
> > |=20
> > constintx =3D0;// west const=20
> > intconstx =3D0;// east const=20
> > |=20
> >=20
> > One of the arguments I've seen for east const is that it's more=20
> > consistent. If you want a const pointer to int, you have to use east=20
> const:=20
> >=20
> > |=20
> > constint*x;// mutable pointer to const int=20
> > int*constx;// const pointer to mutable int=20
> > |=20
> >=20
> > However, what if we could group the types with parentheses?=20
> >=20
> > |=20
> > const(int*)x;// const pointer to mutable int=20
> > |=20
> >=20
> > Is this idea completely flawed, or is there some merit in it?=20
> >=20
>
> Not using raw pointers would be one way to avoid the potential problem.=
=20
>  :-)=20
>
> So making it easier to use raw pointers is perhaps not the highest=20
> priority.=20
>
>
> And when I have a constant pointer, it more often ends up as=20
>
> const int* const=20
>
> where this proposal doesn't help.=20
>
>
>      Bo Persson=20
>
>
And its even worse with multi rank pointers:
int const*const*const pp;
// const (const (const int)*)* ?
The alternative would make const far away from its pointer symbol.


Note that it is already possible to have something similar:
template <class T>
using ptr =3D T*;

const ptr<const ptr<const int>> pp;

--=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/502b2cdf-4b76-436a-9142-469bd2c044d6%40isocpp.or=
g.

------=_Part_1130_1176892375.1533983361799
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>Le samedi 11 ao=C3=BBt 2018 11:50:15 UTC+2, Bo Per=
sson a =C3=A9crit=C2=A0:<blockquote class=3D"gmail_quote" style=3D"margin: =
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 201=
8-08-11 07:33, Justin Bassett wrote:
<br>&gt; We currently have two ways to mark a type as a const type: west co=
nst=20
<br>&gt; and east const:
<br>&gt;=20
<br>&gt; |
<br>&gt; constintx =3D0;// west const
<br>&gt; intconstx =3D0;// east const
<br>&gt; |
<br>&gt;=20
<br>&gt; One of the arguments I&#39;ve seen for east const is that it&#39;s=
 more=20
<br>&gt; consistent. If you want a const pointer to int, you have to use ea=
st const:
<br>&gt;=20
<br>&gt; |
<br>&gt; constint*x;// mutable pointer to const int
<br>&gt; int*constx;// const pointer to mutable int
<br>&gt; |
<br>&gt;=20
<br>&gt; However, what if we could group the types with parentheses?
<br>&gt;=20
<br>&gt; |
<br>&gt; const(int*)x;// const pointer to mutable int
<br>&gt; |
<br>&gt;=20
<br>&gt; Is this idea completely flawed, or is there some merit in it?
<br>&gt;=20
<br>
<br>Not using raw pointers would be one way to avoid the potential problem.=
 =C2=A0:-)
<br>
<br>So making it easier to use raw pointers is perhaps not the highest=20
<br>priority.
<br>
<br>
<br>And when I have a constant pointer, it more often ends up as
<br>
<br>const int* const
<br>
<br>where this proposal doesn&#39;t help.
<br>
<br>
<br>=C2=A0 =C2=A0 =C2=A0Bo Persson
<br>
<br></blockquote><div><br></div><div>And its even worse with multi rank poi=
nters:</div><div><div style=3D"background-color: rgb(250, 250, 250); border=
-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; overflo=
w-wrap: break-word;" class=3D"prettyprint"><code class=3D"prettyprint"><div=
 class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">int</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">const</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">*</span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">const</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">*</span><span style=3D"col=
or: #008;" class=3D"styled-by-prettify">const</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> pp</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br></span><span style=3D"color: #800;" class=3D"styled-=
by-prettify">// const (const (const int)*)* ?</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br></span></div></code></div></div><div=
>The alternative would make const far away from its pointer symbol.<br></di=
v><div><br></div><div><br></div><div>Note that it is already possible to ha=
ve something similar:</div><div><div style=3D"background-color: rgb(250, 25=
0, 250); border-color: rgb(187, 187, 187); border-style: solid; border-widt=
h: 1px; overflow-wrap: break-word;" class=3D"prettyprint"><code class=3D"pr=
ettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=
=3D"styled-by-prettify">template</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">class</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">using</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> ptr </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> T</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">*;</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> ptr</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">const</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> ptr</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;=
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">const</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">&gt;&gt;</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> pp</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br></span></div></code></div><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/502b2cdf-4b76-436a-9142-469bd2c044d6%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/502b2cdf-4b76-436a-9142-469bd2c044d6=
%40isocpp.org</a>.<br />

------=_Part_1130_1176892375.1533983361799--

------=_Part_1129_129490481.1533983361799--

.