Topic: auto(this) method qualifier: factorizing method's
Author: Jonathan Coe <jonathanbcoe@gmail.com>
Date: Sun, 12 Nov 2017 10:36:22 +0000
Raw View
--Apple-Mail-ECFD88FE-E493-43C6-A0E4-69AB64DBA2E1
Content-Type: text/plain; charset="UTF-8"
> On 12 Nov 2017, at 08:57, bastienpenava@gmail.com wrote:
>
> Hi,
>
> the idea is simple, it's to add a "auto(this)" generative method qualifier that would factorizes const, non-const, lvalue and rvalue cv qualifiers.
> It would look something like this:
>
> constexpr auto &operator[](size_t index) auto(this)
> {
> //might use std::is_const_v<decltype(this)> to fine tool for instance.
> //...
> }
>
> And would produce the following methods (if not user-defined):
> constexpr auto &operator[](size_t index) const & { ... }
> constexpr auto &operator[](size_t index] & { ... }
> constexpr auto &operator[](size_t index) && { ... }
>
> As of the reason why, It's to avoid this:
>
> struct C {
> const char & get() const {
> return c;
> }
> char & get() {
> return const_cast<char &>(static_cast<const C &>(*this).get());
> }
> char c;
> };
>
> This code snippet comes from Scott Meyers' "Effective C++" and is still the current one of the "best" solutions.
> The other being simply to copy paste the method and changing the cv qualifier.
This seems rather a small gain for use of syntax that we are currently free to use for something else.
Would this proposed feature help to avoid mistakes or does it just reduce typing?
> --
> 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/5a99fc6b-316a-4958-a240-9304663aa6af%40isocpp.org.
--
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/2AADF95A-4631-4DA2-BD6C-ED938D93AD76%40gmail.com.
--Apple-Mail-ECFD88FE-E493-43C6-A0E4-69AB64DBA2E1
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<html><head><meta http-equiv=3D"content-type" content=3D"text/html; charset=
=3Dutf-8"></head><body dir=3D"auto"><div></div><div><br></div><div><br>On 1=
2 Nov 2017, at 08:57, <a href=3D"mailto:bastienpenava@gmail.com">bastienpen=
ava@gmail.com</a> wrote:<br><br></div><blockquote type=3D"cite"><div><div d=
ir=3D"ltr">Hi,<div><br></div><div>the idea is simple, it's to add a "auto(t=
his)" generative method qualifier that would factorizes const, non-const, l=
value and rvalue cv qualifiers.</div><div>It would look something like this=
:</div><div><br></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;"><code class=3D"prettyprint"><di=
v class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-=
prettify">constexpr</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
auto</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">&</span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">operator</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">[](</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">size_t index</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: #008;=
" class=3D"styled-by-prettify">auto</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">(</span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">this</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br> &nb=
sp;</span><span style=3D"color: #800;" class=3D"styled-by-prettify">//might=
use std::is_const_v<decltype(this)> to fine tool for instance.</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>  =
;</span><span style=3D"color: #800;" class=3D"styled-by-prettify">//...</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">}</span></div></code=
></div><div><br></div><div>And would produce the following methods (if not =
user-defined):</div><div class=3D"prettyprint" style=3D"background-color: r=
gb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; b=
order-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div =
class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">constexpr</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">au=
to</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">&</span><span=
style=3D"color: #008;" class=3D"styled-by-prettify">operator</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">[](</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">size_t index</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: #008;" =
class=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">&</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </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: #660;" class=3D"styled-by-prettify">...</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">constexpr</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">auto</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">&</span><span style=3D"color: #008;" class=3D"styled-by-prettify">ope=
rator</span><span style=3D"color: #660;" class=3D"styled-by-prettify">[](</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">size_t index=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">]</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&</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: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">...</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">}=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">constexpr</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">&</span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">operator</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">[](</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify">size_t index</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: #660;" class=3D"styled-by-pret=
tify">&&</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n 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=
: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"><br></span></div></code></div><div><br></div><=
div>As of the reason why, It's to avoid this:</div><div><br></div><div><pre=
class=3D"lang-cpp prettyprint prettyprinted" style=3D"padding: 5px; font-v=
ariant-numeric: inherit; font-stretch: inherit; line-height: inherit; font-=
family: Consolas, Menlo, Monaco, "Lucida Console", "Liberati=
on Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono=
", "Courier New", monospace, sans-serif; vertical-align: bas=
eline; width: auto; max-height: 600px; overflow: auto; background-color: rg=
b(239, 240, 241); color: rgb(57, 51, 24); word-wrap: normal;"><code style=
=3D"font-style: inherit; font-variant: inherit; font-weight: inherit; font-=
stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monac=
o, "Lucida Console", "Liberation Mono", "DejaVu Sa=
ns Mono", "Bitstream Vera Sans Mono", "Courier New"=
;, monospace, sans-serif; vertical-align: baseline; white-space: inherit;">=
<span class=3D"kwd" style=3D"font-style: inherit; font-variant: inherit; fo=
nt-weight: inherit; font-stretch: inherit; font-size: inherit; line-height:=
inherit; font-family: inherit; vertical-align: baseline; color: rgb(16, 16=
, 148);">struct</span><span class=3D"pln" style=3D"font-style: inherit; fon=
t-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size:=
inherit; line-height: inherit; font-family: inherit; vertical-align: basel=
ine; color: rgb(48, 51, 54);"> C </span><span class=3D"pun" style=3D"font-s=
tyle: inherit; font-variant: inherit; font-weight: inherit; font-stretch: i=
nherit; font-size: inherit; line-height: inherit; font-family: inherit; ver=
tical-align: baseline; color: rgb(48, 51, 54);">{</span><span class=3D"pln"=
style=3D"font-style: inherit; font-variant: inherit; font-weight: inherit;=
font-stretch: inherit; font-size: inherit; line-height: inherit; font-fami=
ly: inherit; vertical-align: baseline; color: rgb(48, 51, 54);">
</span><span class=3D"kwd" style=3D"font-style: inherit; font-variant: in=
herit; font-weight: inherit; font-stretch: inherit; font-size: inherit; lin=
e-height: inherit; font-family: inherit; vertical-align: baseline; color: r=
gb(16, 16, 148);">const</span><span class=3D"pln" style=3D"font-style: inhe=
rit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; fo=
nt-size: inherit; line-height: inherit; font-family: inherit; vertical-alig=
n: baseline; color: rgb(48, 51, 54);"> </span><span class=3D"kwd" style=3D"=
font-style: inherit; font-variant: inherit; font-weight: inherit; font-stre=
tch: inherit; font-size: inherit; line-height: inherit; font-family: inheri=
t; vertical-align: baseline; color: rgb(16, 16, 148);">char</span><span cla=
ss=3D"pln" style=3D"font-style: inherit; font-variant: inherit; font-weight=
: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit;=
font-family: inherit; vertical-align: baseline; color: rgb(48, 51, 54);"> =
</span><span class=3D"pun" style=3D"font-style: inherit; font-variant: inhe=
rit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-=
height: inherit; font-family: inherit; vertical-align: baseline; color: rgb=
(48, 51, 54);">&</span><span class=3D"pln" style=3D"font-style: inherit=
; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-=
size: inherit; line-height: inherit; font-family: inherit; vertical-align: =
baseline; color: rgb(48, 51, 54);"> get</span><span class=3D"pun" style=3D"=
font-style: inherit; font-variant: inherit; font-weight: inherit; font-stre=
tch: inherit; font-size: inherit; line-height: inherit; font-family: inheri=
t; vertical-align: baseline; color: rgb(48, 51, 54);">()</span><span class=
=3D"pln" style=3D"font-style: inherit; font-variant: inherit; font-weight: =
inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; f=
ont-family: inherit; vertical-align: baseline; color: rgb(48, 51, 54);"> </=
span><span class=3D"kwd" style=3D"font-style: inherit; font-variant: inheri=
t; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-he=
ight: inherit; font-family: inherit; vertical-align: baseline; color: rgb(1=
6, 16, 148);">const</span><span class=3D"pln" style=3D"font-style: inherit;=
font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-s=
ize: inherit; line-height: inherit; font-family: inherit; vertical-align: b=
aseline; color: rgb(48, 51, 54);"> </span><span class=3D"pun" style=3D"font=
-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch:=
inherit; font-size: inherit; line-height: inherit; font-family: inherit; v=
ertical-align: baseline; color: rgb(48, 51, 54);">{</span><span class=3D"pl=
n" style=3D"font-style: inherit; font-variant: inherit; font-weight: inheri=
t; font-stretch: inherit; font-size: inherit; line-height: inherit; font-fa=
mily: inherit; vertical-align: baseline; color: rgb(48, 51, 54);">
</span><span class=3D"kwd" style=3D"font-style: inherit; font-variant: =
inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; l=
ine-height: inherit; font-family: inherit; vertical-align: baseline; color:=
rgb(16, 16, 148);">return</span><span class=3D"pln" style=3D"font-style: i=
nherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit;=
font-size: inherit; line-height: inherit; font-family: inherit; vertical-a=
lign: baseline; color: rgb(48, 51, 54);"> c</span><span class=3D"pun" style=
=3D"font-style: inherit; font-variant: inherit; font-weight: inherit; font-=
stretch: inherit; font-size: inherit; line-height: inherit; font-family: in=
herit; vertical-align: baseline; color: rgb(48, 51, 54);">;</span><span cla=
ss=3D"pln" style=3D"font-style: inherit; font-variant: inherit; font-weight=
: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit;=
font-family: inherit; vertical-align: baseline; color: rgb(48, 51, 54);">
</span><span class=3D"pun" style=3D"font-style: inherit; font-variant: in=
herit; font-weight: inherit; font-stretch: inherit; font-size: inherit; lin=
e-height: inherit; font-family: inherit; vertical-align: baseline; color: r=
gb(48, 51, 54);">}</span><span class=3D"pln" style=3D"font-style: inherit; =
font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-si=
ze: inherit; line-height: inherit; font-family: inherit; vertical-align: ba=
seline; color: rgb(48, 51, 54);">
</span><span class=3D"kwd" style=3D"font-style: inherit; font-variant: in=
herit; font-weight: inherit; font-stretch: inherit; font-size: inherit; lin=
e-height: inherit; font-family: inherit; vertical-align: baseline; color: r=
gb(16, 16, 148);">char</span><span class=3D"pln" style=3D"font-style: inher=
it; font-variant: inherit; font-weight: inherit; font-stretch: inherit; fon=
t-size: inherit; line-height: inherit; font-family: inherit; vertical-align=
: baseline; color: rgb(48, 51, 54);"> </span><span class=3D"pun" style=3D"f=
ont-style: inherit; font-variant: inherit; font-weight: inherit; font-stret=
ch: inherit; font-size: inherit; line-height: inherit; font-family: inherit=
; vertical-align: baseline; color: rgb(48, 51, 54);">&</span><span clas=
s=3D"pln" style=3D"font-style: inherit; font-variant: inherit; font-weight:=
inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; =
font-family: inherit; vertical-align: baseline; color: rgb(48, 51, 54);"> g=
et</span><span class=3D"pun" style=3D"font-style: inherit; font-variant: in=
herit; font-weight: inherit; font-stretch: inherit; font-size: inherit; lin=
e-height: inherit; font-family: inherit; vertical-align: baseline; color: r=
gb(48, 51, 54);">()</span><span class=3D"pln" style=3D"font-style: inherit;=
font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-s=
ize: inherit; line-height: inherit; font-family: inherit; vertical-align: b=
aseline; color: rgb(48, 51, 54);"> </span><span class=3D"pun" style=3D"font=
-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch:=
inherit; font-size: inherit; line-height: inherit; font-family: inherit; v=
ertical-align: baseline; color: rgb(48, 51, 54);">{</span><span class=3D"pl=
n" style=3D"font-style: inherit; font-variant: inherit; font-weight: inheri=
t; font-stretch: inherit; font-size: inherit; line-height: inherit; font-fa=
mily: inherit; vertical-align: baseline; color: rgb(48, 51, 54);">
</span><span class=3D"kwd" style=3D"font-style: inherit; font-variant: =
inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; l=
ine-height: inherit; font-family: inherit; vertical-align: baseline; color:=
rgb(16, 16, 148);">return</span><span class=3D"pln" style=3D"font-style: i=
nherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit;=
font-size: inherit; line-height: inherit; font-family: inherit; vertical-a=
lign: baseline; color: rgb(48, 51, 54);"> </span><span class=3D"kwd" style=
=3D"font-style: inherit; font-variant: inherit; font-weight: inherit; font-=
stretch: inherit; font-size: inherit; line-height: inherit; font-family: in=
herit; vertical-align: baseline; color: rgb(16, 16, 148);">const_cast</span=
><span class=3D"pun" style=3D"font-style: inherit; font-variant: inherit; f=
ont-weight: inherit; font-stretch: inherit; font-size: inherit; line-height=
: inherit; font-family: inherit; vertical-align: baseline; color: rgb(48, 5=
1, 54);"><</span><span class=3D"kwd" style=3D"font-style: inherit; font-=
variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: i=
nherit; line-height: inherit; font-family: inherit; vertical-align: baselin=
e; color: rgb(16, 16, 148);">char</span><span class=3D"pln" style=3D"font-s=
tyle: inherit; font-variant: inherit; font-weight: inherit; font-stretch: i=
nherit; font-size: inherit; line-height: inherit; font-family: inherit; ver=
tical-align: baseline; color: rgb(48, 51, 54);"> </span><span class=3D"pun"=
style=3D"font-style: inherit; font-variant: inherit; font-weight: inherit;=
font-stretch: inherit; font-size: inherit; line-height: inherit; font-fami=
ly: inherit; vertical-align: baseline; color: rgb(48, 51, 54);">&>(<=
/span><span class=3D"kwd" style=3D"font-style: inherit; font-variant: inher=
it; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-h=
eight: inherit; font-family: inherit; vertical-align: baseline; color: rgb(=
16, 16, 148);">static_cast</span><span class=3D"pun" style=3D"font-style: i=
nherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit;=
font-size: inherit; line-height: inherit; font-family: inherit; vertical-a=
lign: baseline; color: rgb(48, 51, 54);"><</span><span class=3D"kwd" sty=
le=3D"font-style: inherit; font-variant: inherit; font-weight: inherit; fon=
t-stretch: inherit; font-size: inherit; line-height: inherit; font-family: =
inherit; vertical-align: baseline; color: rgb(16, 16, 148);">const</span><s=
pan class=3D"pln" style=3D"font-style: inherit; font-variant: inherit; font=
-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: i=
nherit; font-family: inherit; vertical-align: baseline; color: rgb(48, 51, =
54);"> C </span><span class=3D"pun" style=3D"font-style: inherit; font-vari=
ant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inher=
it; line-height: inherit; font-family: inherit; vertical-align: baseline; c=
olor: rgb(48, 51, 54);">&>(*</span><span class=3D"kwd" style=3D"font=
-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch:=
inherit; font-size: inherit; line-height: inherit; font-family: inherit; v=
ertical-align: baseline; color: rgb(16, 16, 148);">this</span><span class=
=3D"pun" style=3D"font-style: inherit; font-variant: inherit; font-weight: =
inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; f=
ont-family: inherit; vertical-align: baseline; color: rgb(48, 51, 54);">).<=
/span><span class=3D"pln" style=3D"font-style: inherit; font-variant: inher=
it; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-h=
eight: inherit; font-family: inherit; vertical-align: baseline; color: rgb(=
48, 51, 54);">get</span><span class=3D"pun" style=3D"font-style: inherit; f=
ont-variant: inherit; font-weight: inherit; font-stretch: inherit; font-siz=
e: inherit; line-height: inherit; font-family: inherit; vertical-align: bas=
eline; color: rgb(48, 51, 54);">());</span><span class=3D"pln" style=3D"fon=
t-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch=
: inherit; font-size: inherit; line-height: inherit; font-family: inherit; =
vertical-align: baseline; color: rgb(48, 51, 54);">
</span><span class=3D"pun" style=3D"font-style: inherit; font-variant: in=
herit; font-weight: inherit; font-stretch: inherit; font-size: inherit; lin=
e-height: inherit; font-family: inherit; vertical-align: baseline; color: r=
gb(48, 51, 54);">}</span><span class=3D"pln" style=3D"font-style: inherit; =
font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-si=
ze: inherit; line-height: inherit; font-family: inherit; vertical-align: ba=
seline; color: rgb(48, 51, 54);">
</span><span class=3D"kwd" style=3D"font-style: inherit; font-variant: in=
herit; font-weight: inherit; font-stretch: inherit; font-size: inherit; lin=
e-height: inherit; font-family: inherit; vertical-align: baseline; color: r=
gb(16, 16, 148);">char</span><span class=3D"pln" style=3D"font-style: inher=
it; font-variant: inherit; font-weight: inherit; font-stretch: inherit; fon=
t-size: inherit; line-height: inherit; font-family: inherit; vertical-align=
: baseline; color: rgb(48, 51, 54);"> c</span><span class=3D"pun" style=3D"=
font-style: inherit; font-variant: inherit; font-weight: inherit; font-stre=
tch: inherit; font-size: inherit; line-height: inherit; font-family: inheri=
t; vertical-align: baseline; color: rgb(48, 51, 54);">;</span><span class=
=3D"pln" style=3D"font-style: inherit; font-variant: inherit; font-weight: =
inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; f=
ont-family: inherit; vertical-align: baseline; color: rgb(48, 51, 54);">
</span><span class=3D"pun" style=3D"font-style: inherit; font-variant: inhe=
rit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-=
height: inherit; font-family: inherit; vertical-align: baseline; color: rgb=
(48, 51, 54);">};</span></code></pre></div><div><br></div>This code snippet=
comes from Scott Meyers' "Effective C++" and is still the current one of t=
he "best" solutions.<br>The other being simply to copy paste the method and=
changing the cv qualifier.</div></div></blockquote><div><br></div>This see=
ms rather a small gain for use of syntax that we are currently free to use =
for something else.<div><br></div><div>Would this proposed feature help to =
avoid mistakes or does it just reduce typing?<br><blockquote type=3D"cite">=
<div>
<p></p>
-- <br>
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" 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/5a99fc6b-316a-4958-a240-9304663aa6af%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.goo=
gle.com/a/isocpp.org/d/msgid/std-proposals/5a99fc6b-316a-4958-a240-9304663a=
a6af%40isocpp.org</a>.<br>
</div></blockquote></div></body></html>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/2AADF95A-4631-4DA2-BD6C-ED938D93AD76%=
40gmail.com?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/2AADF95A-4631-4DA2-BD6C-ED938D93AD76%=
40gmail.com</a>.<br />
--Apple-Mail-ECFD88FE-E493-43C6-A0E4-69AB64DBA2E1--
.
Author: bastienpenava@gmail.com
Date: Sun, 12 Nov 2017 03:11:53 -0800 (PST)
Raw View
------=_Part_4299_740829923.1510485114081
Content-Type: multipart/alternative;
boundary="----=_Part_4300_775386145.1510485114082"
------=_Part_4300_775386145.1510485114082
Content-Type: text/plain; charset="UTF-8"
On Sunday, November 12, 2017 at 11:36:29 AM UTC+1, Jonathan Coe wrote:
>
>
>
> On 12 Nov 2017, at 08:57, bastie...@gmail.com <javascript:> wrote:
>
> Hi,
>
> the idea is simple, it's to add a "auto(this)" generative method qualifier
> that would factorizes const, non-const, lvalue and rvalue cv qualifiers.
> It would look something like this:
>
> constexpr auto &operator[](size_t index) auto(this)
> {
> //might use std::is_const_v<decltype(this)> to fine tool for instance.
> //...
> }
>
> And would produce the following methods (if not user-defined):
> constexpr auto &operator[](size_t index) const & { ... }
> constexpr auto &operator[](size_t index] & { ... }
> constexpr auto &operator[](size_t index) && { ... }
>
> As of the reason why, It's to avoid this:
>
> struct C {
> const char & get() const {
> return c;
> }
> char & get() {
> return const_cast<char &>(static_cast<const C &>(*this).get());
> }
> char c;};
>
>
> This code snippet comes from Scott Meyers' "Effective C++" and is still
> the current one of the "best" solutions.
> The other being simply to copy paste the method and changing the cv
> qualifier.
>
>
> This seems rather a small gain for use of syntax that we are currently
> free to use for something else.
>
> Would this proposed feature help to avoid mistakes or does it just reduce
> typing?
>
> --
> 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-proposal...@isocpp.org <javascript:>.
> To post to this group, send email to std-pr...@isocpp.org <javascript:>.
> To view this discussion on the web visit
> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/5a99fc6b-316a-4958-a240-9304663aa6af%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/5a99fc6b-316a-4958-a240-9304663aa6af%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>
>
I'm open to any suggestion on the syntax front, I just used that one
because it doesn't add a new keyword and at this place of the method
declaration doesn't mean anything (no -> beforehand, auto is not legal here
currently)
As for "help to avoid mistakes or does it just reduce typing", I believe it
would be easier to teach than the const_cast method and therefore would the
"missing const qualifier" issues; it would also simplify the work of
library writers and make it more accessible.
For instance someone without much library background might just write a
non-const method then, sometime later due to a compile error, find out that
he can't use it with a const object, add the const qualifier, finds that he
can't modify his data now and look online for a solution, copy paste it and
forget it.
As for copy pasting, in the example the method is fairly simple but that's
not always the case. In those situations the const_cast is the best
solution so far.
My issue with that solution is that if you don't know it you won't use it
and seems generally off.
--
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/0e920467-fd51-44e7-a3b8-090311744acb%40isocpp.org.
------=_Part_4300_775386145.1510485114082
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Sunday, November 12, 2017 at 11:36:29 AM UTC+1, Jonatha=
n Coe wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-lef=
t: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"auto">=
<div></div><div><br></div><div><br>On 12 Nov 2017, at 08:57, <a href=3D"jav=
ascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"FF117PTpAAAJ" rel=3D"n=
ofollow" onmousedown=3D"this.href=3D'javascript:';return true;" onc=
lick=3D"this.href=3D'javascript:';return true;">bastie...@gmail.com=
</a> wrote:<br><br></div><blockquote type=3D"cite"><div><div dir=3D"ltr">Hi=
,<div><br></div><div>the idea is simple, it's to add a "auto(this)=
" generative method qualifier that would factorizes const, non-const, =
lvalue and rvalue cv qualifiers.</div><div>It would look something like thi=
s:</div><div><br></div><div style=3D"background-color:rgb(250,250,250);bord=
er-color:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:bre=
ak-word"><code><div><span style=3D"color:#008">constexpr</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">auto</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">&</span><span style=
=3D"color:#008">operator</span><span style=3D"color:#660">[](</span><span s=
tyle=3D"color:#000">size_t index</span><span style=3D"color:#660">)</span><=
span style=3D"color:#000"> </span><span style=3D"color:#008">auto</span><sp=
an style=3D"color:#660">(</span><span style=3D"color:#008">this</span><span=
style=3D"color:#660">)</span><span style=3D"color:#000"><br></span><span s=
tyle=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0</s=
pan><span style=3D"color:#800">//might use std::is_const_v<decltype(this=
)<wbr>> to fine tool for instance.</span><span style=3D"color:#000"><br>=
=C2=A0 =C2=A0</span><span style=3D"color:#800">//...</span><span style=3D"c=
olor:#000"><br></span><span style=3D"color:#660">}</span></div></code></div=
><div><br></div><div>And would produce the following methods (if not user-d=
efined):</div><div style=3D"background-color:rgb(250,250,250);border-color:=
rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:break-word">=
<code><div><span style=3D"color:#008">constexpr</span><span style=3D"color:=
#000"> </span><span style=3D"color:#008">auto</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#660">&</span><span style=3D"color:#00=
8">operator</span><span style=3D"color:#660">[](</span><span style=3D"color=
:#000">size_t index</span><span style=3D"color:#660">)</span><span style=3D=
"color:#000"> </span><span style=3D"color:#008">const</span><span style=3D"=
color:#000"> </span><span style=3D"color:#660">&</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#660">{</span><span style=3D"color:=
#000"> </span><span style=3D"color:#660">...</span><span style=3D"color:#00=
0"> </span><span style=3D"color:#660">}</span><span style=3D"color:#000"><b=
r></span><span style=3D"color:#008">constexpr</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#008">auto</span><span style=3D"color:#000=
"> </span><span style=3D"color:#660">&</span><span style=3D"color:#008"=
>operator</span><span style=3D"color:#660">[](</span><span style=3D"color:#=
000">size_t index</span><span style=3D"color:#660">]</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#660">&</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#660">{</span><span style=3D"color:#=
000"> </span><span style=3D"color:#660">...</span><span style=3D"color:#000=
"> </span><span style=3D"color:#660">}</span><span style=3D"color:#000"><br=
></span><span style=3D"color:#008">constexpr</span><span style=3D"color:#00=
0"> </span><span style=3D"color:#008">auto</span><span style=3D"color:#000"=
> </span><span style=3D"color:#660">&</span><span style=3D"color:#008">=
operator</span><span style=3D"color:#660">[](</span><span style=3D"color:#0=
00">size_t index</span><span style=3D"color:#660">)</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#660">&&</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#660">...</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#660">}</span><span style=3D"color:#00=
0"><br></span></div></code></div><div><br></div><div>As of the reason why, =
It's to avoid this:</div><div><br></div><div><pre style=3D"padding:5px;=
font-stretch:inherit;line-height:inherit;font-family:Consolas,Menlo,Monaco,=
"Lucida Console","Liberation Mono","DejaVu Sans Mo=
no","Bitstream Vera Sans Mono","Courier New",monos=
pace,sans-serif;vertical-align:baseline;width:auto;max-height:600px;overflo=
w:auto;background-color:rgb(239,240,241);color:rgb(57,51,24);word-wrap:norm=
al"><code style=3D"font-style:inherit;font-variant:inherit;font-weight:inhe=
rit;font-stretch:inherit;line-height:inherit;font-family:Consolas,Menlo,Mon=
aco,"Lucida Console","Liberation Mono","DejaVu San=
s Mono","Bitstream Vera Sans Mono","Courier New",m=
onospace,sans-serif;vertical-align:baseline;white-space:inherit"><span styl=
e=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-stret=
ch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertic=
al-align:baseline;color:rgb(16,16,148)">struct</span><span style=3D"font-st=
yle:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;f=
ont-size:inherit;line-height:inherit;font-family:inherit;vertical-align:bas=
eline;color:rgb(48,51,54)"> C </span><span style=3D"font-style:inherit;font=
-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit=
;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(=
48,51,54)">{</span><span style=3D"font-style:inherit;font-variant:inherit;f=
ont-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inher=
it;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">
</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight=
:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-fa=
mily:inherit;vertical-align:baseline;color:rgb(16,16,148)">const</span><spa=
n style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font=
-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;=
vertical-align:baseline;color:rgb(48,51,54)"> </span><span style=3D"font-st=
yle:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;f=
ont-size:inherit;line-height:inherit;font-family:inherit;vertical-align:bas=
eline;color:rgb(16,16,148)">char</span><span style=3D"font-style:inherit;fo=
nt-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inher=
it;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rg=
b(48,51,54)"> </span><span style=3D"font-style:inherit;font-variant:inherit=
;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inh=
erit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">&=
</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight:i=
nherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-fami=
ly:inherit;vertical-align:baseline;color:rgb(48,51,54)"> get</span><span st=
yle=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-str=
etch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vert=
ical-align:baseline;color:rgb(48,51,54)">()</span><span style=3D"font-style=
:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font=
-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseli=
ne;color:rgb(48,51,54)"> </span><span style=3D"font-style:inherit;font-vari=
ant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line=
-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(16,16=
,148)">const</span><span style=3D"font-style:inherit;font-variant:inherit;f=
ont-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inher=
it;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)"> </span=
><span style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit=
;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inh=
erit;vertical-align:baseline;color:rgb(48,51,54)">{</span><span style=3D"fo=
nt-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inhe=
rit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-alig=
n:baseline;color:rgb(48,51,54)">
</span><span style=3D"font-style:inherit;font-variant:inherit;font-weig=
ht:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-=
family:inherit;vertical-align:baseline;color:rgb(16,16,148)">return</span><=
span style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;f=
ont-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inher=
it;vertical-align:baseline;color:rgb(48,51,54)"> c</span><span style=3D"fon=
t-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inher=
it;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align=
:baseline;color:rgb(48,51,54)">;</span><span style=3D"font-style:inherit;fo=
nt-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inher=
it;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rg=
b(48,51,54)">
</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight=
:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-fa=
mily:inherit;vertical-align:baseline;color:rgb(48,51,54)">}</span><span sty=
le=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-stre=
tch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;verti=
cal-align:baseline;color:rgb(48,51,54)">
</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight=
:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-fa=
mily:inherit;vertical-align:baseline;color:rgb(16,16,148)">char</span><span=
style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-=
stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;v=
ertical-align:baseline;color:rgb(48,51,54)"> </span><span style=3D"font-sty=
le:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;fo=
nt-size:inherit;line-height:inherit;font-family:inherit;vertical-align:base=
line;color:rgb(48,51,54)">&</span><span style=3D"font-style:inherit;fon=
t-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inheri=
t;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb=
(48,51,54)"> get</span><span style=3D"font-style:inherit;font-variant:inher=
it;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:i=
nherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">()<=
/span><span style=3D"font-style:inherit;font-variant:inherit;font-weight:in=
herit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-famil=
y:inherit;vertical-align:baseline;color:rgb(48,51,54)"> </span><span style=
=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretc=
h:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertica=
l-align:baseline;color:rgb(48,51,54)">{</span><span style=3D"font-style:inh=
erit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-siz=
e:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;c=
olor:rgb(48,51,54)">
</span><span style=3D"font-style:inherit;font-variant:inherit;font-weig=
ht:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-=
family:inherit;vertical-align:baseline;color:rgb(16,16,148)">return</span><=
span style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;f=
ont-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inher=
it;vertical-align:baseline;color:rgb(48,51,54)"> </span><span style=3D"font=
-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inheri=
t;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:=
baseline;color:rgb(16,16,148)">const_cast</span><span style=3D"font-style:i=
nherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-s=
ize:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline=
;color:rgb(48,51,54)"><</span><span style=3D"font-style:inherit;font-var=
iant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;lin=
e-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(16,1=
6,148)">char</span><span style=3D"font-style:inherit;font-variant:inherit;f=
ont-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inher=
it;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)"> </span=
><span style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit=
;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inh=
erit;vertical-align:baseline;color:rgb(48,51,54)">&>(</span><span st=
yle=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-str=
etch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vert=
ical-align:baseline;color:rgb(16,16,148)">static_cast</span><span style=3D"=
font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:in=
herit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-al=
ign:baseline;color:rgb(48,51,54)"><</span><span style=3D"font-style:inhe=
rit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size=
:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;co=
lor:rgb(16,16,148)">const</span><span style=3D"font-style:inherit;font-vari=
ant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line=
-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48,51=
,54)"> C </span><span style=3D"font-style:inherit;font-variant:inherit;font=
-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;=
font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">&>(=
*</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight:=
inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-fam=
ily:inherit;vertical-align:baseline;color:rgb(16,16,148)">this</span><span =
style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-s=
tretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;ve=
rtical-align:baseline;color:rgb(48,51,54)">).</span><span style=3D"font-sty=
le:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;fo=
nt-size:inherit;line-height:inherit;font-family:inherit;vertical-align:base=
line;color:rgb(48,51,54)">get</span><span style=3D"font-style:inherit;font-=
variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;=
line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(4=
8,51,54)">());</span><span style=3D"font-style:inherit;font-variant:inherit=
;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inh=
erit;font-family:inherit;vertical-align:baseline;color:rgb(48,51,54)">
</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight=
:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-fa=
mily:inherit;vertical-align:baseline;color:rgb(48,51,54)">}</span><span sty=
le=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-stre=
tch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;verti=
cal-align:baseline;color:rgb(48,51,54)">
</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight=
:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-fa=
mily:inherit;vertical-align:baseline;color:rgb(16,16,148)">char</span><span=
style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-=
stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;v=
ertical-align:baseline;color:rgb(48,51,54)"> c</span><span style=3D"font-st=
yle:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;f=
ont-size:inherit;line-height:inherit;font-family:inherit;vertical-align:bas=
eline;color:rgb(48,51,54)">;</span><span style=3D"font-style:inherit;font-v=
ariant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;l=
ine-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(48=
,51,54)">
</span><span style=3D"font-style:inherit;font-variant:inherit;font-weight:i=
nherit;font-stretch:inherit;font-size:inherit;line-height:inherit;font-fami=
ly:inherit;vertical-align:baseline;color:rgb(48,51,54)">};</span></code></p=
re></div><div><br></div>This code snippet comes from Scott Meyers' &quo=
t;Effective C++" and is still the current one of the "best" =
solutions.<br>The other being simply to copy paste the method and changing =
the cv qualifier.</div></div></blockquote><div><br></div>This seems rather =
a small gain for use of syntax that we are currently free to use for someth=
ing else.<div><br></div><div>Would this proposed feature help to avoid mist=
akes or does it just reduce typing?<br><blockquote type=3D"cite"><div>
<p></p>
-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
FF117PTpAAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:&=
#39;;return true;" onclick=3D"this.href=3D'javascript:';return true=
;">std-proposal...@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"javascript:" target=3D"_bla=
nk" gdf-obfuscated-mailto=3D"FF117PTpAAAJ" rel=3D"nofollow" onmousedown=3D"=
this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'=
;javascript:';return true;">std-pr...@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/5a99fc6b-316a-4958-a240-9304663aa6af%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank" =
rel=3D"nofollow" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/5a99fc6b-316a-4958-a240-9304663aa6af%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/5a99fc6b-316a-4958-a240-9304663aa6af%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/5a99fc6b-316a-4958-<wbr>a240-=
9304663aa6af%40isocpp.org</a><wbr>.<br></div></blockquote></div></div></blo=
ckquote><div><br></div><div>I'm open to any suggestion on the syntax fr=
ont, I just used that one because it doesn't add a new keyword and at t=
his place of the method declaration doesn't mean anything (no -> bef=
orehand, auto is not legal here currently)</div><div>As for "help to a=
void mistakes or does it just reduce typing", I believe it would be ea=
sier to teach than the const_cast method and therefore would the "miss=
ing const qualifier" issues; it would also simplify the work of librar=
y writers and make it more accessible.</div><div>For instance someone witho=
ut much library background might just write a non-const method then, someti=
me later due to a compile error, find out that he can't use it with a c=
onst object, add the const qualifier, finds that he can't modify his da=
ta now and look online for a solution, copy paste it and forget it.</div><d=
iv>As for copy pasting, in the example the method is fairly simple but that=
's not always the case. In those situations the const_cast is the best =
solution so far.<br></div><div>My issue with that solution is that if you d=
on't know it you won't use it and seems generally off.</div><div><b=
r></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/0e920467-fd51-44e7-a3b8-090311744acb%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/0e920467-fd51-44e7-a3b8-090311744acb=
%40isocpp.org</a>.<br />
------=_Part_4300_775386145.1510485114082--
------=_Part_4299_740829923.1510485114081--
.
Author: bastienpenava@gmail.com
Date: Sun, 12 Nov 2017 03:36:00 -0800 (PST)
Raw View
------=_Part_4265_1079372497.1510486560904
Content-Type: multipart/alternative;
boundary="----=_Part_4266_436974967.1510486560904"
------=_Part_4266_436974967.1510486560904
Content-Type: text/plain; charset="UTF-8"
Also something I just realized is that it could be translated into:
template<class This>
return_type method_name(This* this, ...)
{
}
And could allow for something akin to templated this from Dlang:
interface Addable(T)
{
final R add(this R)(T t)
{
return cast(R)this; // cast is necessary, but safe, wouldn't be required in C++ }
}
class List(T) : Addable!T
{
List remove(T t)
{
return this;
}
}
void main()
{
auto list = new List!int;
list.add(1).remove(1); // ok, call the method Addable!int.add!(List!int);}
For this specific example Concepts are a better solution but I feel that I
could be useful in some cases.
Also with this proposal the cast wouldn't be required as "this" would be a
template argument.
Used with concepts this could make parent method that are usable only if
the child type follows certain requirements.
That being said It would also prevent those function from be declared
virtual.
--
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/0b8a5f74-876b-4bb3-92ae-c49baa0f9197%40isocpp.org.
------=_Part_4266_436974967.1510486560904
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Also something I just realized is that it could be transla=
ted into:<div><br><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;"><code class=3D"prettyprint"><d=
iv class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by=
-prettify">template</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify"><</span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">class</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #606;" class=3D"styled-by-prettify">This</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">></span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br>return_type method_=
name</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</spa=
n><span style=3D"color: #606;" class=3D"styled-by-prettify">This</span><spa=
n 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=
: #008;" class=3D"styled-by-prettify">this</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: #660;" class=3D"style=
d-by-prettify">...)</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span></di=
v></code></div><div><br></div><div>And could allow for something akin to te=
mplated this from Dlang:</div><div><pre class=3D"d_code notranslate" style=
=3D"padding: 1ex; border-width: 1px; border-style: solid; border-color: rgb=
(204, 204, 204); font-size: small; font-family: Consolas, "Bitstream V=
era Sans Mono", "Andale Mono", Monaco, "DejaVu Sans Mon=
o", "Lucida Console", monospace; background: rgb(252, 252, 2=
52); border-radius: 4px; line-height: normal; width: auto; white-space: pre=
-wrap; word-wrap: break-word; overflow: auto; color: rgb(51, 51, 51);"><spa=
n class=3D"d_keyword" style=3D"color: rgb(64, 64, 220);">interface</span> A=
ddable(T)
{
<span class=3D"d_keyword" style=3D"color: rgb(64, 64, 220);">final</spa=
n> R add(<span class=3D"d_keyword" style=3D"color: rgb(64, 64, 220);">this<=
/span> R)(T t)
{
<span class=3D"d_keyword" style=3D"color: rgb(64, 64, 220);">return=
</span> <span class=3D"d_keyword" style=3D"color: rgb(64, 64, 220);">cast</=
span>(R)<span class=3D"d_keyword" style=3D"color: rgb(64, 64, 220);">this</=
span>; <span class=3D"d_comment" style=3D"color: rgb(153, 153, 153);">// c=
ast is necessary, but safe, wouldn't be required in C++
</span> }
}
<span class=3D"d_keyword" style=3D"color: rgb(64, 64, 220);">class</span> L=
ist(T) : Addable!T
{
List remove(T t)
{
<span class=3D"d_keyword" style=3D"color: rgb(64, 64, 220);">return=
</span> <span class=3D"d_keyword" style=3D"color: rgb(64, 64, 220);">this</=
span>;
}
}
<span class=3D"d_keyword" style=3D"color: rgb(64, 64, 220);">void</span> ma=
in()
{
<span class=3D"d_keyword" style=3D"color: rgb(64, 64, 220);">auto</span=
> list =3D <span class=3D"d_keyword" style=3D"color: rgb(64, 64, 220);">new=
</span> List!<span class=3D"d_keyword" style=3D"color: rgb(64, 64, 220);">i=
nt</span>;
list.add(1).remove(1); <span class=3D"d_comment" style=3D"color: rgb(1=
53, 153, 153);">// ok, call the method Addable!int.add!(List!int);
</span>}</pre></div><div><br></div><div>For this specific example Concepts =
are a better solution but I feel that I could be useful in some cases.</div=
></div><div>Also with this proposal the cast wouldn't be required as &q=
uot;this" would be a template argument.</div><div>Used with concepts t=
his could make parent method that are usable only if the child type follows=
certain requirements.</div><div><br></div><div>That being said It would al=
so prevent those function from be declared virtual.</div></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/0b8a5f74-876b-4bb3-92ae-c49baa0f9197%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/0b8a5f74-876b-4bb3-92ae-c49baa0f9197=
%40isocpp.org</a>.<br />
------=_Part_4266_436974967.1510486560904--
------=_Part_4265_1079372497.1510486560904--
.
Author: Giovanni Piero Deretta <gpderetta@gmail.com>
Date: Mon, 13 Nov 2017 01:58:12 -0800 (PST)
Raw View
------=_Part_7135_697887768.1510567092924
Content-Type: multipart/alternative;
boundary="----=_Part_7136_1834107739.1510567092924"
------=_Part_7136_1834107739.1510567092924
Content-Type: text/plain; charset="UTF-8"
On Sunday, November 12, 2017 at 11:36:01 AM UTC, bastie...@gmail.com wrote:
>
> Also something I just realized is that it could be translated into:
>
> template<class This>
> return_type method_name(This* this, ...)
> {
> }
>
>
Simple and fairly obvious. +1. To bikeshed it a bit, maybe allow (or even
require) this to be a reference as well (so it can supersede & and &&
qualifications). In 20 years we can deprecate implicit 'this'.
--
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/7c562a18-def9-4cea-b79f-5ab9170c7398%40isocpp.org.
------=_Part_7136_1834107739.1510567092924
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Sunday, November 12, 2017 at 11:36:01 AM UTC, bastie...=
@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"l=
tr">Also something I just realized is that it could be translated into:<div=
><br><div><div 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><div><span style=3D"color:#008">template</span><span style=3D"color:#660"=
><</span><span style=3D"color:#008">class</span><span style=3D"color:#00=
0"> </span><span style=3D"color:#606">This</span><span style=3D"color:#660"=
>></span><span style=3D"color:#000"><br>return_type method_name</span><s=
pan style=3D"color:#660">(</span><span style=3D"color:#606">This</span><spa=
n style=3D"color:#660">*</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#008">this</span><span style=3D"color:#660">,</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></span><span style=3D"color:#660">}</span></div></code>=
</div></div><br></div></div></blockquote><div><br><br>Simple and fairly obv=
ious. +1. To bikeshed it a bit, maybe allow (or even require) this to be a =
reference as well (so it can supersede & and && qualifications)=
.. In 20 years we can deprecate implicit 'this'.<br></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/7c562a18-def9-4cea-b79f-5ab9170c7398%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/7c562a18-def9-4cea-b79f-5ab9170c7398=
%40isocpp.org</a>.<br />
------=_Part_7136_1834107739.1510567092924--
------=_Part_7135_697887768.1510567092924--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Mon, 13 Nov 2017 10:48:15 -0800
Raw View
On segunda-feira, 13 de novembro de 2017 01:58:12 PST Giovanni Piero Deretta
wrote:
> On Sunday, November 12, 2017 at 11:36:01 AM UTC, bastie...@gmail.com wrote:
> > Also something I just realized is that it could be translated into:
> >
> > template<class This>
> > return_type method_name(This* this, ...)
> > {
> > }
>
> Simple and fairly obvious. +1. To bikeshed it a bit, maybe allow (or even
> require) this to be a reference as well (so it can supersede & and &&
> qualifications). In 20 years we can deprecate implicit 'this'.
This syntax would also enable the pass-this-by-value request
See the thread[1] with subject "Passing *this by value".
[1] https://groups.google.com/a/isocpp.org/forum/#!searchin/std-proposals/mutz
$20value/std-proposals/9Lf_yMmTK5o/ErsxzUCBBgAJ
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
--
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/4782833.emFSlLkMm8%40tjmaciei-mobl1.
.
Author: Alberto Barbati <albertobarbati@gmail.com>
Date: Tue, 14 Nov 2017 02:28:26 -0800 (PST)
Raw View
------=_Part_10393_1919079700.1510655307087
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
The problem with your syntax is that you don=E2=80=99t get enough control. =
If I can, I would propose the following:
auto f() const? // synthesizes with and without const
auto f() volatile? // synthesizes with and without volatile
auto f() &&? // synthesizes with & and &&
These can be combined in any way, for example:
auto f() const? &&? // synthesizes four versions: &, &&, const& and const&&
And even:
auto f() const? && // synthesizes two versions: && and const&&
The only issue to solve is that since a single definition now produces more=
than one function, the order in which the two synthesized functions are de=
fined may become significant, but that can be addressed somehow.
Just my two eurocent.
--=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/a9a4f146-3b6e-4961-8713-3551d623c15b%40isocpp.or=
g.
------=_Part_10393_1919079700.1510655307087--
.
Author: Simon Brand <simon@codeplay.com>
Date: Tue, 14 Nov 2017 10:40:16 +0000
Raw View
Ga=C5=A1per A=C5=BEman, Ben Deane, Barry Revzin and I already have a reason=
ably=20
large proposal for a feature which addresses this issue. In fact, we=20
were working on different proposals independently and are joining them=20
together. Feel free to message me if you'd like to give feedback on our=20
current draft.
On 13/11/17 18:48, Thiago Macieira wrote:
> On segunda-feira, 13 de novembro de 2017 01:58:12 PST Giovanni Piero Dere=
tta
> wrote:
>> On Sunday, November 12, 2017 at 11:36:01 AM UTC, bastie...@gmail.com wro=
te:
>>> Also something I just realized is that it could be translated into:
>>>
>>> template<class This>
>>> return_type method_name(This* this, ...)
>>> {
>>> }
>> Simple and fairly obvious. +1. To bikeshed it a bit, maybe allow (or eve=
n
>> require) this to be a reference as well (so it can supersede & and &&
>> qualifications). In 20 years we can deprecate implicit 'this'.
> This syntax would also enable the pass-this-by-value request
>
> See the thread[1] with subject "Passing *this by value".
>
> [1] https://groups.google.com/a/isocpp.org/forum/#!searchin/std-proposals=
/mutz
> $20value/std-proposals/9Lf_yMmTK5o/ErsxzUCBBgAJ
>
--=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/da80185f-0bdd-603e-b595-96569899a2e6%40codeplay.=
com.
.
Author: bastienpenava@gmail.com
Date: Tue, 14 Nov 2017 03:48:43 -0800 (PST)
Raw View
------=_Part_9120_1552392299.1510660124016
Content-Type: multipart/alternative;
boundary="----=_Part_9121_1826090169.1510660124016"
------=_Part_9121_1826090169.1510660124016
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
On Tuesday, November 14, 2017 at 11:28:27 AM UTC+1, Alberto Barbati wrote:
>
> The problem with your syntax is that you don=E2=80=99t get enough control=
.. If I=20
> can, I would propose the following:=20
>
> auto f() const? // synthesizes with and without const=20
> auto f() volatile? // synthesizes with and without volatile=20
> auto f() &&? // synthesizes with & and &&=20
>
> These can be combined in any way, for example:=20
>
> auto f() const? &&? // synthesizes four versions: &, &&, const& and=20
> const&&=20
>
> And even:=20
>
> auto f() const? && // synthesizes two versions: && and const&&=20
>
> The only issue to solve is that since a single definition now produces=20
> more than one function, the order in which the two synthesized functions=
=20
> are defined may become significant, but that can be addressed somehow.=20
>
> Just my two eurocent.=20
>
> The discussion move past this idea.
What would you say to either:
- *auto(this)* making this a templated argument
- allowing explicit "this" front argument in method declaration:
struct A
{
template<class T>
decltype(auto) method(T&& this) { return this; }
void other(A& this) {}
};
struct B :A
{
};
static_assert(std::is_same_v<decltype(B{}.method()),B>);
Both approach would result in factorizing cv qualifiers, allowing value or=
=20
reference this, a parent method to receive the type of its child, etc...
--=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/f13bbcde-4a0e-4c69-95a0-c82e71e1ce16%40isocpp.or=
g.
------=_Part_9121_1826090169.1510660124016
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, November 14, 2017 at 11:28:27 AM UTC+1, Albert=
o Barbati wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin=
-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">The problem wi=
th your syntax is that you don=E2=80=99t get enough control. If I can, I wo=
uld propose the following:
<br>
<br>auto f() const? // synthesizes with and without const
<br>auto f() volatile? // synthesizes with and without volatile
<br>auto f() &&? // synthesizes with & and &&
<br>
<br>These can be combined in any way, for example:
<br>
<br>auto f() const? &&? // synthesizes four versions: &, &&=
amp;, const& and const&&
<br>
<br>And even:
<br>
<br>auto f() const? && // synthesizes two versions: && and =
const&&
<br>
<br>The only issue to solve is that since a single definition now produces =
more than one function, the order in which the two synthesized functions ar=
e defined may become significant, but that can be addressed somehow.
<br>
<br>Just my two eurocent.
<br>
<br></blockquote><div>The discussion move past this idea.</div><div>What wo=
uld you say to either:</div><div>- <i>auto(this)</i> making this a template=
d argument</div><div>- allowing explicit "this" front argument in=
method declaration:</div><div class=3D"prettyprint" style=3D"background-co=
lor: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: so=
lid; border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"=
><div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled=
-by-prettify">struct</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> A<br></span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>=C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">te=
mplate</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><=
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">class</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> T</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">></span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">decltype</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> method</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">T</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">&&</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">this</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </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: #008;" =
class=3D"styled-by-prettify">return</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">this</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: #660;" class=3D"styled-by-prettify">}</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>=C2=A0 </=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">void</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> other</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">A</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: #008;" class=3D=
"styled-by-prettify">this</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{}<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">};</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">struct</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> B </span><span style=3D"color:=
#660;" class=3D"styled-by-prettify">:</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify">A<br></span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br></span><font color=3D"#666600"><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">};</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">static_assert</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">std</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">is_same_v</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
"><</span><span style=3D"color: #008;" class=3D"styled-by-prettify">decl=
type</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">B</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">{}.</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">method</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">()),</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">B</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">>);</span></font></div></code></div><div><br></=
div><div>Both approach would result in factorizing cv qualifiers, allowing =
value or reference this, a parent method to receive the type of its child, =
etc...</div><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" 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/f13bbcde-4a0e-4c69-95a0-c82e71e1ce16%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/f13bbcde-4a0e-4c69-95a0-c82e71e1ce16=
%40isocpp.org</a>.<br />
------=_Part_9121_1826090169.1510660124016--
------=_Part_9120_1552392299.1510660124016--
.
Author: Alberto Barbati <albertobarbati@gmail.com>
Date: Tue, 14 Nov 2017 04:27:04 -0800 (PST)
Raw View
------=_Part_3626_1461156291.1510662424153
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Il giorno marted=C3=AC 14 novembre 2017 12:48:44 UTC+1, bastie...@gmail.com=
ha scritto:
> What would you say to either:
> - auto(this) making this a templated argument
As I said, I believe this is an inferior solution, since it provides less c=
ontrol.
> - allowing explicit "this" front argument in method declaration:
We would almost get this for free if we had the =E2=80=9Cunified function s=
yntax=E2=80=9D, which is a much more promising and forward-looking idea.
--=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/7bfab6cf-20de-4228-ac5b-baf47b8e2a0b%40isocpp.or=
g.
------=_Part_3626_1461156291.1510662424153--
.
Author: bastienpenava@gmail.com
Date: Tue, 14 Nov 2017 04:35:36 -0800 (PST)
Raw View
------=_Part_5456_1774674253.1510662936377
Content-Type: multipart/alternative;
boundary="----=_Part_5457_562841831.1510662936377"
------=_Part_5457_562841831.1510662936377
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
On Tuesday, November 14, 2017 at 1:27:04 PM UTC+1, Alberto Barbati wrote:
> We would almost get this for free if we had the =E2=80=9Cunified function=
syntax=E2=80=9D,=20
> which is a much more promising and forward-looking idea.=20
>
> Except that we're never going to get UCS to bjarne's dismay.
And also this solution would allow to inject the members of the this=20
parameter in the function scope, so no, not inferior.
Actually could be a not-controversial way have it if we'd allow this kind=
=20
of method to be declared at scope-level.
void print(int this)
{
}
int main()
{
42.print();
print(42);
void (*f)(int) =3D &print;
}
--=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/0ec2b24b-c98b-46b1-a65e-2b704c544b7b%40isocpp.or=
g.
------=_Part_5457_562841831.1510662936377
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, November 14, 2017 at 1:27:04 PM UTC+1, Alberto=
Barbati wrote:<div><blockquote class=3D"gmail_quote" style=3D"margin: 0;ma=
rgin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">We would a=
lmost get this for free if we had the =E2=80=9Cunified function syntax=E2=
=80=9D, which is a much more promising and forward-looking idea.
<br>
<br></blockquote><div>Except that we're never going to get UCS to=C2=A0=
bjarne's dismay.</div><div>And also this solution would allow to inject=
the members of the this parameter in the function scope, so no, not inferi=
or.</div><div>Actually could be a not-controversial way have it if we'd=
allow this kind of method to be declared at scope-level.</div></div><div><=
br></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;"><code class=3D"prettyprint"><div class=3D"su=
bprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">voi=
d</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #008;" class=3D"styled-by-prettify">print</span><span =
style=3D"color: #660;" 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"styled-by-prettify"> </span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">this</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
></span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> main</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #066;" c=
lass=3D"styled-by-prettify">42.print</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">();</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">print</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #066;" class=3D"style=
d-by-prettify">42</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br></span><span style=3D"color: #000;" class=3D"styled-by-prettify">=C2=A0 =
=C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">voi=
d</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">(*</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify">f</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">)(</span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">int</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&</sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">print</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">}</span></div></code></div><div><b=
r></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/0ec2b24b-c98b-46b1-a65e-2b704c544b7b%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/0ec2b24b-c98b-46b1-a65e-2b704c544b7b=
%40isocpp.org</a>.<br />
------=_Part_5457_562841831.1510662936377--
------=_Part_5456_1774674253.1510662936377--
.