Topic: Feature regarding const and volatile method qualifiers.


Author: eyalz800@gmail.com
Date: Wed, 3 Aug 2016 15:02:25 -0700 (PDT)
Raw View
------=_Part_16_932604995.1470261745207
Content-Type: multipart/alternative;
 boundary="----=_Part_17_2112247565.1470261745213"

------=_Part_17_2112247565.1470261745213
Content-Type: text/plain; charset=UTF-8

Hi.
I recently ran into a problem that made me wonder whether const and
volatile method qualifiers can be
turned on/off given a boolean constant expression , like the noexcept
specifier, and even be deduced from the call site.

Let's assume we have some kind of archive that saves and loads objects,
calling their serialize method.
The archive can either be loading type, or saving type, and of course, we
want to be able to save const objects.
Let 'a' be an object we want to save and load, if we don't want to
duplicate code with two serialization methods, one for const and one for
non-const,
we need its method to accept both const and non const references of 'a', we
can achieve this with a template and SFINAE:
class a
{
public:
    template <typename _Archive, typename _Self, typename...,
        typename = std::enable_if_t<std::is_base_of_v<a, _Self>>
    >
    static void serialize(_Archive & archive, _Self & self)
    {
        archive(self.x, self.y, self.z);
    }

private:
    int x;
    int y;
    int z;
};

In my opinion, using the static method to answer this requirement is a bad
practice, if const qualifier was metaprogrammable like noexcept,
we could have done this instead:
class a
{
public:
    template <typename _Archive>
    void serialize(_Archive & archive) const(_Archive::is_saving())
    {
        archive(x, y, z);
    }

private:
    int x;
    int y;
    int z;
};


To take this to the next level, usually we want our methods to work on
const and non const versions of the objects.
Lets look at the simplest form of the issue, and make a version of
string::c_str that works on both const and non const string objects,
we can do the following with a relatively simple SFINAE, one can do
something like this (I didn't test it but the idea is clear):

class string
{
public:
    template <typename _Self, typename...,
        typename = std::enable_if_t<std::is_base_of_v<string, _Self>>
    >
    static std::conditional_t<std::is_const_v<_Self>, const char, char> *
c_str(_Self & self)
    {
        return self.m_data;
    }

private:
    char * m_data;
};


While the above example works, in my opinion, a better practice would be to
replace it with the following code:
class string
{
public:
    const(auto) char * c_str() const(auto)
    {
        return m_data;
    }

private:
    char * m_data;
};

Here we turn the const qualifier on and off, and it solves the problem
elegantly.
This qualifier deduction feature can even be applied to the serialization
example.
I probably need to think how it acts with reference qualifiers as well.

What do you think?
Eyal.

--
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/a7424985-ff9e-449e-9c94-ab7a94cfc338%40isocpp.org.

------=_Part_17_2112247565.1470261745213
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi.<div>I recently ran into a problem that made me wonder =
whether const and volatile method qualifiers can be=C2=A0</div><div>turned =
on/off given a boolean constant expression , like the noexcept specifier, a=
nd even be deduced from the call site.</div><div><br></div><div>Let&#39;s a=
ssume we have some kind of archive that saves and loads objects, calling th=
eir serialize method.</div><div>The archive can either be loading type, or =
saving type, and of course, we want to be able to save const objects.</div>=
<div>Let &#39;a&#39; be an object we want to save and load, if we don&#39;t=
 want to duplicate code with two serialization methods, one for const and o=
ne for non-const,</div><div>we need its method to accept both const and non=
 const references of &#39;a&#39;, we can achieve this with a template and S=
FINAE:</div><div><div class=3D"prettyprint" style=3D"border: 1px solid rgb(=
187, 187, 187); word-wrap: break-word; background-color: rgb(250, 250, 250)=
;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D=
"color: #008;" class=3D"styled-by-prettify">class</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> a<br></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><span style=3D"color: #008;" class=3D"=
styled-by-prettify">public</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">:</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">template</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-prettify">ty=
pename</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> _Ar=
chive</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">typename</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><font color=3D"#6=
66600"><span style=3D"color: #000;" class=3D"styled-by-prettify">_Self</spa=
n><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: #008;" class=3D"styled-by-prettify">typename</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">...,</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">typename</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> std</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">enable_if_t</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify">std</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">is_base_of_v</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">&lt;</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"> _Self</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">&gt;&gt;</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></font><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">=C2=A0 =C2=A0 </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">static</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">void</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> serialize</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify">_Archive </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">&amp;</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> archive</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> _Self </span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">&amp;</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">se=
lf</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><font =
color=3D"#666600"><span style=3D"color: #000;" class=3D"styled-by-prettify"=
>=C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 archive</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">(</span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">self</span><span style=3D"color: #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"styled-by-prettify"> </span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">self</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">y</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: #008;" class=3D"styled-by-pre=
ttify">self</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>.</span><span style=3D"color: #000;" class=3D"styled-by-prettify">z</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br></span></font><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify">=C2=A0 =C2=A0 </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">private</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: #008;" class=3D"styled-by-prettify">int</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> x</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>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">int</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> y</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">int</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> z</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">};</span></div></co=
de></div><div><br></div>In my opinion, using the static method to answer th=
is requirement is a bad practice, if const qualifier was metaprogrammable l=
ike noexcept,</div><div>we could have done this instead:<br><div class=3D"p=
rettyprint" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break=
-word; background-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><=
div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">class</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> a<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: #008;" class=3D"styled-by-prettify">public</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">template</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">typename</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> _Archive</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"col=
or: #008;" class=3D"styled-by-prettify">void</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> serialize</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">_Archive </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&amp;</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> archive</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">c=
onst</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">_Archive</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">is_saving</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">())</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br></span><font color=3D"#666600=
"><span style=3D"color: #000;" class=3D"styled-by-prettify">=C2=A0 =C2=A0 <=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 archive</span><span style=3D"color: #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"styled-by-prettify"> y</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> z</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></span></font><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">=C2=A0 =C2=A0 </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><span style=3D"color: #008;" class=
=3D"styled-by-prettify">private</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">:</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">int</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> x</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">int</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> y<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">int</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> z</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">};</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br></span></div></code></div><br><br></div><div>T=
o take this to the next level, usually we want our methods to work on const=
 and non const versions of the objects.</div><div>Lets look at the simplest=
 form of the issue, and make a version of string::c_str that works on both =
const and non const string objects,</div><div>we can do the following with =
a relatively simple SFINAE, one can do something like this (I didn&#39;t te=
st it but the idea is clear):</div><div><br></div><div><div class=3D"pretty=
print" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word=
; background-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div c=
lass=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">class</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">string<=
/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 sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">public</span><span style=3D"colo=
r: #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=
: #008;" class=3D"styled-by-prettify">template</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">typename</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> _Self</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: #008;" class=3D"styled-by-prettify">typ=
ename</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 =C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">typename</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> std</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify">enable_if_t</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">std</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify">is_base_of_v</span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">string</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><font color=3D"#000088"><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">_Self</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">&gt;&gt;</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">&gt;</span></font><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">static</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> std</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">conditional_t</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">std</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">is_const_v</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">_Self</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&g=
t;,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">const</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">char</span><span style=3D"co=
lor: #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">char</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">*</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> c_str=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">_Self </span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">self</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: #660=
;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><font color=
=3D"#880000"><span style=3D"color: #008;" class=3D"styled-by-prettify">retu=
rn</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">self</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify">m_data</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">;</span></font><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </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><span style=3D"color: =
#008;" class=3D"styled-by-prettify">private</span><span style=3D"color: #66=
0;" 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: #008=
;" class=3D"styled-by-prettify">char</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">*</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> m_data</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">;</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></d=
iv></code></div><br>While the above example works, in my opinion, a better =
practice would be to=C2=A0</div><div>replace it with the following code:</d=
iv><div><div class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187,=
 187); word-wrap: break-word; background-color: rgb(250, 250, 250);"><code =
class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #=
008;" class=3D"styled-by-prettify">class</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">string</span><span style=3D"color: #000;" class=3D"sty=
led-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></span><span style=3D"color: #008;" class=3D"styled-by-prettify">publ=
ic</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: #008;" class=3D"styled-by-prettify">const</sp=
an><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"> </span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">char</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-pret=
tify"> c_str</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">()</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">const</span><sp=
an 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"co=
lor: #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"col=
or: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">return</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> m_data</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: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color: =
#008;" class=3D"styled-by-prettify">private</span><span style=3D"color: #66=
0;" 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: #008=
;" class=3D"styled-by-prettify">char</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">*</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> m_data</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">;</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></span></div><=
/code></div><br>Here we turn the const qualifier on and off, and it solves =
the problem elegantly.</div><div>This qualifier deduction feature can even =
be applied to the serialization example.</div><div>I probably need to think=
 how it acts with reference qualifiers as well.</div><div><br></div><div>Wh=
at do you think?</div><div>Eyal.</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/a7424985-ff9e-449e-9c94-ab7a94cfc338%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/a7424985-ff9e-449e-9c94-ab7a94cfc338=
%40isocpp.org</a>.<br />

------=_Part_17_2112247565.1470261745213--

------=_Part_16_932604995.1470261745207--

.


Author: eyalz800@gmail.com
Date: Wed, 3 Aug 2016 15:17:40 -0700 (PDT)
Raw View
------=_Part_19_29121970.1470262660736
Content-Type: multipart/alternative;
 boundary="----=_Part_20_144893941.1470262660736"

------=_Part_20_144893941.1470262660736
Content-Type: text/plain; charset=UTF-8

One final note: If you didn't notice, the last example can be made even
simpler using return type deduction:
class string
{
public:
    auto c_str() const(auto)
    {
        return m_data;
    }

private:
    char * m_data;
};


--
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/a012e694-f107-4bda-ade2-2efff116b2c3%40isocpp.org.

------=_Part_20_144893941.1470262660736
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">One final note: If you didn&#39;t notice, the last example=
 can be made even simpler using return type deduction:<div><div class=3D"pr=
ettyprint" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-=
word; background-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><d=
iv class=3D"subprettyprint"><span style=3D"color: rgb(0, 0, 136);"><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">class</span></span><span =
style=3D"color: rgb(0, 0, 0);"><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span></span><span style=3D"color: rgb(0, 0, 136);"><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">string</span></span><spa=
n style=3D"color: rgb(0, 0, 0);"><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br></span></span><span style=3D"color: rgb(102, 102, 0);">=
<span style=3D"color: #660;" class=3D"styled-by-prettify">{</span></span><s=
pan style=3D"color: rgb(0, 0, 0);"><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br></span></span><span style=3D"color: rgb(0, 0, 136);">=
<span style=3D"color: #008;" class=3D"styled-by-prettify">public</span></sp=
an><span style=3D"color: rgb(102, 102, 0);"><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">:</span></span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><font color=3D"#000088"><=
span style=3D"color: #008;" class=3D"styled-by-prettify">auto</span></font>=
<span style=3D"color: rgb(0, 0, 0);"><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> c_str</span></span><span style=3D"color: rgb(102, 102,=
 0);"><span style=3D"color: #660;" class=3D"styled-by-prettify">()</span></=
span><span style=3D"color: rgb(0, 0, 0);"><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span></span><span style=3D"color: rgb(0, 0, 136=
);"><span style=3D"color: #008;" class=3D"styled-by-prettify">const</span><=
/span><span style=3D"color: rgb(102, 102, 0);"><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">(</span></span><span style=3D"color: rgb(0, 0=
, 136);"><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</sp=
an></span><span style=3D"color: rgb(102, 102, 0);"><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">)</span></span><span style=3D"color: rgb(=
0, 0, 0);"><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
=C2=A0 =C2=A0 </span></span><span style=3D"color: rgb(102, 102, 0);"><span =
style=3D"color: #660;" class=3D"styled-by-prettify">{</span></span><span st=
yle=3D"color: rgb(0, 0, 0);"><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span></span><span style=3D"co=
lor: rgb(0, 0, 136);"><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">return</span></span><span style=3D"color: rgb(0, 0, 0);"><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> m_data</span></span><span s=
tyle=3D"color: rgb(102, 102, 0);"><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">;</span></span><span style=3D"color: rgb(0, 0, 0);"><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </spa=
n></span><span style=3D"color: rgb(102, 102, 0);"><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">}</span></span><span style=3D"color: rgb(0=
, 0, 0);"><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br=
></span></span><span style=3D"color: rgb(0, 0, 136);"><span style=3D"color:=
 #008;" class=3D"styled-by-prettify">private</span></span><span style=3D"co=
lor: rgb(102, 102, 0);"><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">:</span></span><span style=3D"color: rgb(0, 0, 0);"><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span></span><=
span style=3D"color: rgb(0, 0, 136);"><span style=3D"color: #008;" class=3D=
"styled-by-prettify">char</span></span><span style=3D"color: rgb(0, 0, 0);"=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span></span><=
span style=3D"color: rgb(102, 102, 0);"><span style=3D"color: #660;" class=
=3D"styled-by-prettify">*</span></span><span style=3D"color: rgb(0, 0, 0);"=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> m_data</span></=
span><span style=3D"color: rgb(102, 102, 0);"><span style=3D"color: #660;" =
class=3D"styled-by-prettify">;</span></span><span style=3D"color: rgb(0, 0,=
 0);"><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span>=
</span><span style=3D"color: rgb(102, 102, 0);"><span style=3D"color: #660;=
" class=3D"styled-by-prettify">};</span></span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br></span></div></code></div><br><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/a012e694-f107-4bda-ade2-2efff116b2c3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/a012e694-f107-4bda-ade2-2efff116b2c3=
%40isocpp.org</a>.<br />

------=_Part_20_144893941.1470262660736--

------=_Part_19_29121970.1470262660736--

.


Author: Thiago Macieira <thiago@macieira.org>
Date: Wed, 03 Aug 2016 18:29:32 -0700
Raw View
On quarta-feira, 3 de agosto de 2016 15:17:40 PDT eyalz800@gmail.com wrote:
> One final note: If you didn't notice, the last example can be made even
> simpler using return type deduction:
> class string
> {
> public:
>     auto c_str() const(auto)
>     {
>         return m_data;
>     }
>
> private:
>     char * m_data;
> };

This doesn't do what you want. A const object makes the member pointer const,
not the pointed data. The above would create a
  char * const c_str() const

which has cv-qualifiers on a primitive, return type (prvalue). It's ignored and
dropped.

--
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/4140964.MMv93v2YFD%40tjmaciei-mobl1.

.


Author: eyalz800@gmail.com
Date: Wed, 3 Aug 2016 22:48:14 -0700 (PDT)
Raw View
------=_Part_207_1282227564.1470289694473
Content-Type: multipart/alternative;
 boundary="----=_Part_208_158824846.1470289694474"

------=_Part_208_158824846.1470289694474
Content-Type: text/plain; charset=UTF-8



On Thursday, August 4, 2016 at 4:29:39 AM UTC+3, Thiago Macieira wrote:
>
> On quarta-feira, 3 de agosto de 2016 15:17:40 PDT eyal...@gmail.com
> <javascript:> wrote:
> > One final note: If you didn't notice, the last example can be made even
> > simpler using return type deduction:
> > class string
> > {
> > public:
> >     auto c_str() const(auto)
> >     {
> >         return m_data;
> >     }
> >
> > private:
> >     char * m_data;
> > };
>
> This doesn't do what you want. A const object makes the member pointer
> const,
> not the pointed data. The above would create a
>          char * const c_str() const
>
> which has cv-qualifiers on a primitive, return type (prvalue). It's
> ignored and
> dropped.
>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
>    Software Architect - Intel Open Source Technology Center
>
>
Good catch! In this example only the explicit version works.
Let this example take its place:
class point
{
public:
    auto & get_x() const(auto)
    {
        return x;
    }

    auto & get_y() const(auto)
    {
        return y;
    }

private:
    int x;
    int y;
};






--
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/8750b776-3297-4744-b786-923194236a33%40isocpp.org.

------=_Part_208_158824846.1470289694474
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Thursday, August 4, 2016 at 4:29:39 AM UTC+3, T=
hiago Macieira wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On quarta=
-feira, 3 de agosto de 2016 15:17:40 PDT <a href=3D"javascript:" target=3D"=
_blank" gdf-obfuscated-mailto=3D"SsxjS_ltBwAJ" rel=3D"nofollow" onmousedown=
=3D"this.href=3D&#39;javascript:&#39;;return true;" onclick=3D"this.href=3D=
&#39;javascript:&#39;;return true;">eyal...@gmail.com</a> wrote:
<br>&gt; One final note: If you didn&#39;t notice, the last example can be =
made even=20
<br>&gt; simpler using return type deduction:
<br>&gt; class string
<br>&gt; {
<br>&gt; public:
<br>&gt; =C2=A0 =C2=A0 auto c_str() const(auto)
<br>&gt; =C2=A0 =C2=A0 {
<br>&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 return m_data;
<br>&gt; =C2=A0 =C2=A0 }
<br>&gt;=20
<br>&gt; private:
<br>&gt; =C2=A0 =C2=A0 char * m_data;
<br>&gt; };
<br>
<br>This doesn&#39;t do what you want. A const object makes the member poin=
ter const,=20
<br>not the pointed data. The above would create a
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0char * const c_st=
r() const
<br>
<br>which has cv-qualifiers on a primitive, return type (prvalue). It&#39;s=
 ignored and=20
<br>dropped.
<br>
<br>--=20
<br>Thiago Macieira - thiago (AT) <a href=3D"http://macieira.info" target=
=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;http://www.goo=
gle.com/url?q\x3dhttp%3A%2F%2Fmacieira.info\x26sa\x3dD\x26sntz\x3d1\x26usg\=
x3dAFQjCNEswDUBNCNanbu7euhqLn_62FW8ag&#39;;return true;" onclick=3D"this.hr=
ef=3D&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fmacieira.info\x26sa\x=
3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEswDUBNCNanbu7euhqLn_62FW8ag&#39;;return t=
rue;">macieira.info</a> - thiago (AT) <a href=3D"http://kde.org" target=3D"=
_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;http://www.google.=
com/url?q\x3dhttp%3A%2F%2Fkde.org\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH=
GRJdo5_JYG1DowztwAHAKs80XSA&#39;;return true;" onclick=3D"this.href=3D&#39;=
http://www.google.com/url?q\x3dhttp%3A%2F%2Fkde.org\x26sa\x3dD\x26sntz\x3d1=
\x26usg\x3dAFQjCNHGRJdo5_JYG1DowztwAHAKs80XSA&#39;;return true;">kde.org</a=
>
<br>=C2=A0 =C2=A0Software Architect - Intel Open Source Technology Center
<br>
<br></blockquote><div><br></div><div>Good catch! In this example only the e=
xplicit version works.</div><div>Let this example take its place:</div><div=
><div class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187); =
word-wrap: break-word; background-color: rgb(250, 250, 250);"><code class=
=3D"prettyprint"><div class=3D"subprettyprint"><font color=3D"#660066"><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">class</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> point<br></span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">public</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: #008;"=
 class=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">&amp;</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> get_x</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">()</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><span st=
yle=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"><br>=C2=A0 =C2=A0 </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">return</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"><br>=C2=A0 =C2=A0 </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br><br>=C2=A0 =C2=A0 </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">&amp;</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> get_y</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">const</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</s=
pan><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 </sp=
an><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 =C2=
=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>return</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> y<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 <br=
></span><span style=3D"color: #008;" class=3D"styled-by-prettify">private</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">int</span><sp=
an 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"><br>=C2=A0 =C2=A0 </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> y</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"st=
yled-by-prettify">};</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br><br><br><br><br></span></font></div></code></div><br><br></di=
v></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/8750b776-3297-4744-b786-923194236a33%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/8750b776-3297-4744-b786-923194236a33=
%40isocpp.org</a>.<br />

------=_Part_208_158824846.1470289694474--

------=_Part_207_1282227564.1470289694473--

.


Author: inkwizytoryankes@gmail.com
Date: Thu, 4 Aug 2016 11:56:52 -0700 (PDT)
Raw View
------=_Part_1196_1088763957.1470337012300
Content-Type: multipart/alternative;
 boundary="----=_Part_1197_1864792400.1470337012300"

------=_Part_1197_1864792400.1470337012300
Content-Type: text/plain; charset=UTF-8



On Thursday, August 4, 2016 at 3:29:39 AM UTC+2, Thiago Macieira wrote:
>
> On quarta-feira, 3 de agosto de 2016 15:17:40 PDT eyal...@gmail.com
> <javascript:> wrote:
> > One final note: If you didn't notice, the last example can be made even
> > simpler using return type deduction:
> > class string
> > {
> > public:
> >     auto c_str() const(auto)
> >     {
> >         return m_data;
> >     }
> >
> > private:
> >     char * m_data;
> > };
>
> This doesn't do what you want. A const object makes the member pointer
> const,
> not the pointed data. The above would create a
>          char * const c_str() const
>
> which has cv-qualifiers on a primitive, return type (prvalue). It's
> ignored and
> dropped.
>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
>    Software Architect - Intel Open Source Technology Center
>
>
This part could be solved by library solution that could propagate constens
into pointers:
https://groups.google.com/a/isocpp.org/forum/?fromgroups#!searchin/std-proposals/propagate/std-proposals/NwLIq4d2-oI/Ajj4kyYUGz8J
I see good synergy between them.

--
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/744ce8f5-3aee-4960-bb7a-d176af678553%40isocpp.org.

------=_Part_1197_1864792400.1470337012300
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Thursday, August 4, 2016 at 3:29:39 AM UTC+2, T=
hiago Macieira wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On quarta=
-feira, 3 de agosto de 2016 15:17:40 PDT <a href=3D"javascript:" target=3D"=
_blank" gdf-obfuscated-mailto=3D"SsxjS_ltBwAJ" rel=3D"nofollow" onmousedown=
=3D"this.href=3D&#39;javascript:&#39;;return true;" onclick=3D"this.href=3D=
&#39;javascript:&#39;;return true;">eyal...@gmail.com</a> wrote:
<br>&gt; One final note: If you didn&#39;t notice, the last example can be =
made even=20
<br>&gt; simpler using return type deduction:
<br>&gt; class string
<br>&gt; {
<br>&gt; public:
<br>&gt; =C2=A0 =C2=A0 auto c_str() const(auto)
<br>&gt; =C2=A0 =C2=A0 {
<br>&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 return m_data;
<br>&gt; =C2=A0 =C2=A0 }
<br>&gt;=20
<br>&gt; private:
<br>&gt; =C2=A0 =C2=A0 char * m_data;
<br>&gt; };
<br>
<br>This doesn&#39;t do what you want. A const object makes the member poin=
ter const,=20
<br>not the pointed data. The above would create a
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0char * const c_st=
r() const
<br>
<br>which has cv-qualifiers on a primitive, return type (prvalue). It&#39;s=
 ignored and=20
<br>dropped.
<br>
<br>--=20
<br>Thiago Macieira - thiago (AT) <a href=3D"http://macieira.info" target=
=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;http://www.goo=
gle.com/url?q\x3dhttp%3A%2F%2Fmacieira.info\x26sa\x3dD\x26sntz\x3d1\x26usg\=
x3dAFQjCNEswDUBNCNanbu7euhqLn_62FW8ag&#39;;return true;" onclick=3D"this.hr=
ef=3D&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fmacieira.info\x26sa\x=
3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEswDUBNCNanbu7euhqLn_62FW8ag&#39;;return t=
rue;">macieira.info</a> - thiago (AT) <a href=3D"http://kde.org" target=3D"=
_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;http://www.google.=
com/url?q\x3dhttp%3A%2F%2Fkde.org\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH=
GRJdo5_JYG1DowztwAHAKs80XSA&#39;;return true;" onclick=3D"this.href=3D&#39;=
http://www.google.com/url?q\x3dhttp%3A%2F%2Fkde.org\x26sa\x3dD\x26sntz\x3d1=
\x26usg\x3dAFQjCNHGRJdo5_JYG1DowztwAHAKs80XSA&#39;;return true;">kde.org</a=
>
<br>=C2=A0 =C2=A0Software Architect - Intel Open Source Technology Center
<br>
<br></blockquote><div><br>This part could be solved by library solution tha=
t could propagate constens into pointers:<br>https://groups.google.com/a/is=
ocpp.org/forum/?fromgroups#!searchin/std-proposals/propagate/std-proposals/=
NwLIq4d2-oI/Ajj4kyYUGz8J<br>I see good synergy between them.<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/744ce8f5-3aee-4960-bb7a-d176af678553%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/744ce8f5-3aee-4960-bb7a-d176af678553=
%40isocpp.org</a>.<br />

------=_Part_1197_1864792400.1470337012300--

------=_Part_1196_1088763957.1470337012300--

.


Author: eyalz800@gmail.com
Date: Sat, 6 Aug 2016 14:14:59 -0700 (PDT)
Raw View
------=_Part_876_544209820.1470518099341
Content-Type: multipart/alternative;
 boundary="----=_Part_877_1574321696.1470518099341"

------=_Part_877_1574321696.1470518099341
Content-Type: text/plain; charset=UTF-8

While this approach is interesting, I still think that it would be great to
enable this method qualifier deduction.
Consider even this extension, allowing both const and volatile qualifiers
to be deduced:

class point
{
public:
    auto & get_x() auto // allow both const and volatile
    {
        return x;
        }

       // Same for get_y

private:
    int x;
    int y;
};



On Thursday, August 4, 2016 at 9:56:52 PM UTC+3, inkwizyt...@gmail.com
wrote:
>
>
>
> On Thursday, August 4, 2016 at 3:29:39 AM UTC+2, Thiago Macieira wrote:
>>
>> On quarta-feira, 3 de agosto de 2016 15:17:40 PDT eyal...@gmail.com
>> wrote:
>> > One final note: If you didn't notice, the last example can be made even
>> > simpler using return type deduction:
>> > class string
>> > {
>> > public:
>> >     auto c_str() const(auto)
>> >     {
>> >         return m_data;
>> >     }
>> >
>> > private:
>> >     char * m_data;
>> > };
>>
>> This doesn't do what you want. A const object makes the member pointer
>> const,
>> not the pointed data. The above would create a
>>          char * const c_str() const
>>
>> which has cv-qualifiers on a primitive, return type (prvalue). It's
>> ignored and
>> dropped.
>>
>> --
>> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
>>    Software Architect - Intel Open Source Technology Center
>>
>>
> This part could be solved by library solution that could propagate
> constens into pointers:
>
> https://groups.google.com/a/isocpp.org/forum/?fromgroups#!searchin/std-proposals/propagate/std-proposals/NwLIq4d2-oI/Ajj4kyYUGz8J
> I see good synergy between them.
>


--
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/1842d2a0-4a86-480c-aed6-ff456d5fc28e%40isocpp.org.

------=_Part_877_1574321696.1470518099341
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">While this approach is interesting, I still think that it =
would be great to enable this method qualifier deduction.<div>Consider even=
 this extension, allowing both const and volatile qualifiers to be deduced:=
</div><div><br></div><div><div class=3D"prettyprint" style=3D"border: 1px s=
olid rgb(187, 187, 187); word-wrap: break-word; background-color: rgb(250, =
250, 250);"><code class=3D"prettyprint"><div class=3D"subprettyprint"><font=
 color=3D"#660066"><span style=3D"color: #008;" class=3D"styled-by-prettify=
">class</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> po=
int<br></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">public</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br></span></font><span style=
=3D"color: #000;" class=3D"styled-by-prettify">=C2=A0 =C2=A0 </span><span s=
tyle=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=
: #660;" class=3D"styled-by-prettify">&amp;</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> get_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 color=3D"#000088"><span style=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: #800;" class=3D=
"styled-by-prettify">// allow both const and volatile</span></font><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">ret=
urn</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> x</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br></span><div style=3D=
"font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255,=
 255);"><span style=3D"color: #000;" class=3D"styled-by-prettify">=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 </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 =C2=A0 =C2=A0 =C2=A0</span><span style=3D"color: #800;" cl=
ass=3D"styled-by-prettify">// Same for get_y</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">private</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></div><font color=3D"#660066"><span style=3D"color: =
#000;" class=3D"styled-by-prettify">=C2=A0 =C2=A0 </span><span style=3D"col=
or: #008;" class=3D"styled-by-prettify">int</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> x</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">int</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> y</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">;</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></font></div></code></div><br><br><br>On Thursday, August 4, 2016 at 9:5=
6:52 PM UTC+3, inkwizyt...@gmail.com wrote:<blockquote class=3D"gmail_quote=
" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding=
-left: 1ex;"><div dir=3D"ltr"><br><br>On Thursday, August 4, 2016 at 3:29:3=
9 AM UTC+2, Thiago Macieira wrote:<blockquote class=3D"gmail_quote" style=
=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"=
>On quarta-feira, 3 de agosto de 2016 15:17:40 PDT <a rel=3D"nofollow">eyal=
....@gmail.com</a> wrote:
<br>&gt; One final note: If you didn&#39;t notice, the last example can be =
made even=20
<br>&gt; simpler using return type deduction:
<br>&gt; class string
<br>&gt; {
<br>&gt; public:
<br>&gt; =C2=A0 =C2=A0 auto c_str() const(auto)
<br>&gt; =C2=A0 =C2=A0 {
<br>&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 return m_data;
<br>&gt; =C2=A0 =C2=A0 }
<br>&gt;=20
<br>&gt; private:
<br>&gt; =C2=A0 =C2=A0 char * m_data;
<br>&gt; };
<br>
<br>This doesn&#39;t do what you want. A const object makes the member poin=
ter const,=20
<br>not the pointed data. The above would create a
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0char * const c_st=
r() const
<br>
<br>which has cv-qualifiers on a primitive, return type (prvalue). It&#39;s=
 ignored and=20
<br>dropped.
<br>
<br>--=20
<br>Thiago Macieira - thiago (AT) <a href=3D"http://macieira.info" rel=3D"n=
ofollow" target=3D"_blank" onmousedown=3D"this.href=3D&#39;http://www.googl=
e.com/url?q\x3dhttp%3A%2F%2Fmacieira.info\x26sa\x3dD\x26sntz\x3d1\x26usg\x3=
dAFQjCNEswDUBNCNanbu7euhqLn_62FW8ag&#39;;return true;" onclick=3D"this.href=
=3D&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fmacieira.info\x26sa\x3d=
D\x26sntz\x3d1\x26usg\x3dAFQjCNEswDUBNCNanbu7euhqLn_62FW8ag&#39;;return tru=
e;">macieira.info</a> - thiago (AT) <a href=3D"http://kde.org" rel=3D"nofol=
low" target=3D"_blank" onmousedown=3D"this.href=3D&#39;http://www.google.co=
m/url?q\x3dhttp%3A%2F%2Fkde.org\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHGR=
Jdo5_JYG1DowztwAHAKs80XSA&#39;;return true;" onclick=3D"this.href=3D&#39;ht=
tp://www.google.com/url?q\x3dhttp%3A%2F%2Fkde.org\x26sa\x3dD\x26sntz\x3d1\x=
26usg\x3dAFQjCNHGRJdo5_JYG1DowztwAHAKs80XSA&#39;;return true;">kde.org</a>
<br>=C2=A0 =C2=A0Software Architect - Intel Open Source Technology Center
<br>
<br></blockquote><div><br>This part could be solved by library solution tha=
t could propagate constens into pointers:<br><a href=3D"https://groups.goog=
le.com/a/isocpp.org/forum/?fromgroups#!searchin/std-proposals/propagate/std=
-proposals/NwLIq4d2-oI/Ajj4kyYUGz8J" target=3D"_blank" rel=3D"nofollow" onm=
ousedown=3D"this.href=3D&#39;https://groups.google.com/a/isocpp.org/forum/?=
fromgroups#!searchin/std-proposals/propagate/std-proposals/NwLIq4d2-oI/Ajj4=
kyYUGz8J&#39;;return true;" onclick=3D"this.href=3D&#39;https://groups.goog=
le.com/a/isocpp.org/forum/?fromgroups#!searchin/std-proposals/propagate/std=
-proposals/NwLIq4d2-oI/Ajj4kyYUGz8J&#39;;return true;">https://groups.googl=
e.com/a/<wbr>isocpp.org/forum/?fromgroups#!<wbr>searchin/std-proposals/<wbr=
>propagate/std-proposals/<wbr>NwLIq4d2-oI/Ajj4kyYUGz8J</a><br>I see good sy=
nergy between them.<br></div></div></blockquote><div>=C2=A0<br></div></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/1842d2a0-4a86-480c-aed6-ff456d5fc28e%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/1842d2a0-4a86-480c-aed6-ff456d5fc28e=
%40isocpp.org</a>.<br />

------=_Part_877_1574321696.1470518099341--

------=_Part_876_544209820.1470518099341--

.


Author: eyalz800@gmail.com
Date: Sat, 6 Aug 2016 14:24:01 -0700 (PDT)
Raw View
------=_Part_2838_2091874903.1470518641536
Content-Type: multipart/alternative;
 boundary="----=_Part_2839_119860002.1470518641538"

------=_Part_2839_119860002.1470518641538
Content-Type: text/plain; charset=UTF-8

We can even argue about efficiency, consider an implementation of
unique_ptr::operator*:

template <typename T>
class unique_ptr
{
public:
    // We deal with all qualifiers with a single overload,
    // even returning an xvalue when able, thus making the code more
efficient.
    auto && operator*() auto &&
    {
        return std::forward<auto>(*this)->m_t;
    }

private:
    T * m_t;
};



On Thursday, August 4, 2016 at 1:02:25 AM UTC+3, eyal...@gmail.com wrote:
>
> Hi.
> I recently ran into a problem that made me wonder whether const and
> volatile method qualifiers can be
> turned on/off given a boolean constant expression , like the noexcept
> specifier, and even be deduced from the call site.
>
> Let's assume we have some kind of archive that saves and loads objects,
> calling their serialize method.
> The archive can either be loading type, or saving type, and of course, we
> want to be able to save const objects.
> Let 'a' be an object we want to save and load, if we don't want to
> duplicate code with two serialization methods, one for const and one for
> non-const,
> we need its method to accept both const and non const references of 'a',
> we can achieve this with a template and SFINAE:
> class a
> {
> public:
>     template <typename _Archive, typename _Self, typename...,
>         typename = std::enable_if_t<std::is_base_of_v<a, _Self>>
>     >
>     static void serialize(_Archive & archive, _Self & self)
>     {
>         archive(self.x, self.y, self.z);
>     }
>
> private:
>     int x;
>     int y;
>     int z;
> };
>
> In my opinion, using the static method to answer this requirement is a bad
> practice, if const qualifier was metaprogrammable like noexcept,
> we could have done this instead:
> class a
> {
> public:
>     template <typename _Archive>
>     void serialize(_Archive & archive) const(_Archive::is_saving())
>     {
>         archive(x, y, z);
>     }
>
> private:
>     int x;
>     int y;
>     int z;
> };
>
>
> To take this to the next level, usually we want our methods to work on
> const and non const versions of the objects.
> Lets look at the simplest form of the issue, and make a version of
> string::c_str that works on both const and non const string objects,
> we can do the following with a relatively simple SFINAE, one can do
> something like this (I didn't test it but the idea is clear):
>
> class string
> {
> public:
>     template <typename _Self, typename...,
>         typename = std::enable_if_t<std::is_base_of_v<string, _Self>>
>     >
>     static std::conditional_t<std::is_const_v<_Self>, const char, char> *
> c_str(_Self & self)
>     {
>         return self.m_data;
>     }
>
> private:
>     char * m_data;
> };
>
>
> While the above example works, in my opinion, a better practice would be
> to
> replace it with the following code:
> class string
> {
> public:
>     const(auto) char * c_str() const(auto)
>     {
>         return m_data;
>     }
>
> private:
>     char * m_data;
> };
>
> Here we turn the const qualifier on and off, and it solves the problem
> elegantly.
> This qualifier deduction feature can even be applied to the serialization
> example.
> I probably need to think how it acts with reference qualifiers as well.
>
> What do you think?
> Eyal.
>

--
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/620406e2-5ab9-44cc-9561-b1af054a6404%40isocpp.org.

------=_Part_2839_119860002.1470518641538
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">We can even argue about efficiency, consider an implementa=
tion of unique_ptr::operator*:<div><br></div><div><div class=3D"prettyprint=
" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; bac=
kground-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=
=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">template</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">typename</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> T</span><span s=
tyle=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"co=
lor: #008;" class=3D"styled-by-prettify">class</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> unique_ptr<br></span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">public</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">:</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #800;" class=
=3D"styled-by-prettify">// We deal with all qualifiers with a single overlo=
ad,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=
=A0 =C2=A0 </span><span style=3D"color: #800;" class=3D"styled-by-prettify"=
>// even returning an xvalue when able, thus </span><span style=3D"color: #=
800;" class=3D"styled-by-prettify">making the code more efficient.</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 <=
/span><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">&amp;&amp;</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #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"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">&amp;&amp;</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #008;"=
 class=3D"styled-by-prettify">return</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> std</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">forward</span><span style=3D"color: #080;" class=3D"styled-by-p=
rettify">&lt;auto&gt;</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">(*</span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">this</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)-&=
gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">m_t</sp=
an><font color=3D"#008800"><span style=3D"color: #660;" class=3D"styled-by-=
prettify">;</span></font><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">private</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 T </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">*</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> m_t</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">};</span></div></code></div=
><br><br><br>On Thursday, August 4, 2016 at 1:02:25 AM UTC+3, eyal...@gmail=
..com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left=
: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">Hi=
..<div>I recently ran into a problem that made me wonder whether const and v=
olatile method qualifiers can be=C2=A0</div><div>turned on/off given a bool=
ean constant expression , like the noexcept specifier, and even be deduced =
from the call site.</div><div><br></div><div>Let&#39;s assume we have some =
kind of archive that saves and loads objects, calling their serialize metho=
d.</div><div>The archive can either be loading type, or saving type, and of=
 course, we want to be able to save const objects.</div><div>Let &#39;a&#39=
; be an object we want to save and load, if we don&#39;t want to duplicate =
code with two serialization methods, one for const and one for non-const,</=
div><div>we need its method to accept both const and non const references o=
f &#39;a&#39;, we can achieve this with a template and SFINAE:</div><div><d=
iv style=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;backgrou=
nd-color:rgb(250,250,250)"><code><div><span style=3D"color:#008">class</spa=
n><span style=3D"color:#000"> a<br></span><span style=3D"color:#660">{</spa=
n><span style=3D"color:#000"><br></span><span style=3D"color:#008">public</=
span><span style=3D"color:#660">:</span><span style=3D"color:#000"><br>=C2=
=A0 =C2=A0 </span><span style=3D"color:#008">template</span><span style=3D"=
color:#000"> </span><span style=3D"color:#660">&lt;</span><span style=3D"co=
lor:#008">typename</span><span style=3D"color:#000"> _Archive</span><span s=
tyle=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">typename</span><span style=3D"color:#000"> </span><font col=
or=3D"#666600"><span style=3D"color:#000">_Self</span><span style=3D"color:=
#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:#008"=
>typename</span><span style=3D"color:#660">...,</span><span style=3D"color:=
#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">typ=
ename</span><span style=3D"color:#000"> </span><span style=3D"color:#660">=
=3D</span><span style=3D"color:#000"> std</span><span style=3D"color:#660">=
::</span><span style=3D"color:#000">enable_if_t</span><span style=3D"color:=
#660">&lt;</span><span style=3D"color:#000">std</span><span style=3D"color:=
#660">::</span><span style=3D"color:#000">is_base_<wbr>of_v</span><span sty=
le=3D"color:#660">&lt;</span><span style=3D"color:#000">a</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> _Self</span><span style=
=3D"color:#660">&gt;&gt;</span><span style=3D"color:#000"><br></span></font=
><span style=3D"color:#000">=C2=A0 =C2=A0 </span><span style=3D"color:#660"=
>&gt;</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=
=3D"color:#008">static</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">void</span><span style=3D"color:#000"> serialize</span><spa=
n style=3D"color:#660">(</span><span style=3D"color:#000">_Archive </span><=
span style=3D"color:#660">&amp;</span><span style=3D"color:#000"> archive</=
span><span style=3D"color:#660">,</span><span style=3D"color:#000"> _Self <=
/span><span style=3D"color:#660">&amp;</span><span style=3D"color:#000"> </=
span><span style=3D"color:#008">self</span><span style=3D"color:#660">)</sp=
an><span style=3D"color:#000"><br></span><font color=3D"#666600"><span styl=
e=3D"color:#000">=C2=A0 =C2=A0 </span><span style=3D"color:#660">{</span><s=
pan style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 archive</span><spa=
n style=3D"color:#660">(</span><span style=3D"color:#008">self</span><span =
style=3D"color:#660">.</span><span style=3D"color:#000">x</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#008">self</span><span style=3D"color:#660">.</span><span style=3D"col=
or:#000">y</span><span style=3D"color:#660">,</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#008">self</span><span style=3D"color:#660=
">.</span><span style=3D"color:#000">z</span><span style=3D"color:#660">);<=
/span><span style=3D"color:#000"><br></span></font><span style=3D"color:#00=
0">=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span><span style=3D"c=
olor:#000"><br><br></span><span style=3D"color:#008">private</span><span st=
yle=3D"color:#660">:</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </s=
pan><span style=3D"color:#008">int</span><span style=3D"color:#000"> x</spa=
n><span style=3D"color:#660">;</span><span style=3D"color:#000"><br>=C2=A0 =
=C2=A0 </span><span style=3D"color:#008">int</span><span style=3D"color:#00=
0"> y</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><=
br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">int</span><span style=3D=
"color:#000"> z</span><span style=3D"color:#660">;</span><span style=3D"col=
or:#000"><br></span><span style=3D"color:#660">};</span></div></code></div>=
<div><br></div>In my opinion, using the static method to answer this requir=
ement is a bad practice, if const qualifier was metaprogrammable like noexc=
ept,</div><div>we could have done this instead:<br><div style=3D"border:1px=
 solid rgb(187,187,187);word-wrap:break-word;background-color:rgb(250,250,2=
50)"><code><div><span style=3D"color:#008">class</span><span style=3D"color=
:#000"> a<br></span><span style=3D"color:#660">{</span><span style=3D"color=
:#000"><br></span><span style=3D"color:#008">public</span><span style=3D"co=
lor:#660">:</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span=
 style=3D"color:#008">template</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#660">&lt;</span><span style=3D"color:#008">typename</spa=
n><span style=3D"color:#000"> _Archive</span><span style=3D"color:#660">&gt=
;</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"=
color:#008">void</span><span style=3D"color:#000"> serialize</span><span st=
yle=3D"color:#660">(</span><span style=3D"color:#000">_Archive </span><span=
 style=3D"color:#660">&amp;</span><span style=3D"color:#000"> archive</span=
><span style=3D"color:#660">)</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#008">const</span><span style=3D"color:#660">(</span><span=
 style=3D"color:#000">_Archive</span><span style=3D"color:#660">::</span><s=
pan style=3D"color:#000">is_saving</span><span style=3D"color:#660">())</sp=
an><span style=3D"color:#000"><br></span><font color=3D"#666600"><span styl=
e=3D"color:#000">=C2=A0 =C2=A0 </span><span style=3D"color:#660">{</span><s=
pan style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 archive</span><spa=
n style=3D"color:#660">(</span><span style=3D"color:#000">x</span><span sty=
le=3D"color:#660">,</span><span style=3D"color:#000"> y</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> z</span><span style=3D"=
color:#660">);</span><span style=3D"color:#000"><br></span></font><span sty=
le=3D"color:#000">=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span><=
span style=3D"color:#000"><br><br></span><span style=3D"color:#008">private=
</span><span style=3D"color:#660">:</span><span style=3D"color:#000"><br>=
=C2=A0 =C2=A0 </span><span style=3D"color:#008">int</span><span style=3D"co=
lor:#000"> x</span><span style=3D"color:#660">;</span><span style=3D"color:=
#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">int</span><span s=
tyle=3D"color:#000"> y</span><span style=3D"color:#660">;</span><span style=
=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">int</sp=
an><span style=3D"color:#000"> z</span><span style=3D"color:#660">;</span><=
span style=3D"color:#000"><br></span><span style=3D"color:#660">};</span><s=
pan style=3D"color:#000"><br></span></div></code></div><br><br></div><div>T=
o take this to the next level, usually we want our methods to work on const=
 and non const versions of the objects.</div><div>Lets look at the simplest=
 form of the issue, and make a version of string::c_str that works on both =
const and non const string objects,</div><div>we can do the following with =
a relatively simple SFINAE, one can do something like this (I didn&#39;t te=
st it but the idea is clear):</div><div><br></div><div><div style=3D"border=
:1px solid rgb(187,187,187);word-wrap:break-word;background-color:rgb(250,2=
50,250)"><code><div><span style=3D"color:#008">class</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#008">string</span><span style=3D"c=
olor:#000"><br></span><span style=3D"color:#660">{</span><span style=3D"col=
or:#000"><br></span><span style=3D"color:#008">public</span><span style=3D"=
color:#660">:</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><sp=
an style=3D"color:#008">template</span><span style=3D"color:#000"> </span><=
span style=3D"color:#660">&lt;</span><span style=3D"color:#008">typename</s=
pan><span style=3D"color:#000"> _Self</span><span style=3D"color:#660">,</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#008">typename<=
/span><span style=3D"color:#660">...,</span><span style=3D"color:#000"> <br=
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">typename</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#660">=3D</span>=
<span style=3D"color:#000"> std</span><span style=3D"color:#660">::</span><=
span style=3D"color:#000">enable_if_t</span><span style=3D"color:#660">&lt;=
</span><span style=3D"color:#000">std</span><span style=3D"color:#660">::</=
span><span style=3D"color:#000">is_base_<wbr>of_v</span><span style=3D"colo=
r:#660">&lt;</span><span style=3D"color:#008">string</span><span style=3D"c=
olor:#660">,</span><span style=3D"color:#000"> </span><font color=3D"#00008=
8"><span style=3D"color:#000">_Self</span><span style=3D"color:#660">&gt;&g=
t;</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D=
"color:#660">&gt;</span></font><span style=3D"color:#000"><br>=C2=A0 =C2=A0=
 </span><span style=3D"color:#008">static</span><span style=3D"color:#000">=
 std</span><span style=3D"color:#660">::</span><span style=3D"color:#000">c=
onditional_t</span><span style=3D"color:#660">&lt;</span><span style=3D"col=
or:#000">std</span><span style=3D"color:#660">::</span><span style=3D"color=
:#000">is_<wbr>const_v</span><span style=3D"color:#660">&lt;</span><span st=
yle=3D"color:#000">_Self</span><span style=3D"color:#660">&gt;,</span><span=
 style=3D"color:#000"> </span><span style=3D"color:#008">const</span><span =
style=3D"color:#000"> </span><span style=3D"color:#008">char</span><span st=
yle=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">char</span><span style=3D"color:#660">&gt;</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#660">*</span><span style=3D"=
color:#000"> c_str</span><span style=3D"color:#660">(</span><span style=3D"=
color:#000">_Self </span><span style=3D"color:#660">&amp;</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">self</span><span style=
=3D"color:#660">)</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span=
><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 </span><font color=3D"#880000"><span style=3D"color:#0=
08">return</span><span style=3D"color:#000"> </span><span style=3D"color:#0=
08">self</span><span style=3D"color:#660">.</span><span style=3D"color:#000=
">m_data</span><span style=3D"color:#660">;</span></font><span style=3D"col=
or:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span><span =
style=3D"color:#000"><br><br></span><span style=3D"color:#008">private</spa=
n><span style=3D"color:#660">:</span><span style=3D"color:#000"><br>=C2=A0 =
=C2=A0 </span><span style=3D"color:#008">char</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#660">*</span><span style=3D"color:#000"> =
m_data</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><br></span></div></code></div><br>While the above example works, in my o=
pinion, a better practice would be to=C2=A0</div><div>replace it with the f=
ollowing code:</div><div><div style=3D"border:1px solid rgb(187,187,187);wo=
rd-wrap:break-word;background-color:rgb(250,250,250)"><code><div><span styl=
e=3D"color:#008">class</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">string</span><span style=3D"color:#000"><br></span><span st=
yle=3D"color:#660">{</span><span style=3D"color:#000"><br></span><span styl=
e=3D"color:#008">public</span><span style=3D"color:#660">:</span><span styl=
e=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">const<=
/span><span style=3D"color:#660">(</span><span style=3D"color:#008">auto</s=
pan><span style=3D"color:#660">)</span><span style=3D"color:#000"> </span><=
span style=3D"color:#008">char</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#660">*</span><span style=3D"color:#000"> c_str</span><sp=
an style=3D"color:#660">()</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#008">const</span><span style=3D"color:#660">(</span><span st=
yle=3D"color:#008">auto</span><span style=3D"color:#660">)</span><span styl=
e=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">{</spa=
n><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span s=
tyle=3D"color:#008">return</span><span style=3D"color:#000"> m_data</span><=
span style=3D"color:#660">;</span><span style=3D"color:#000"><br>=C2=A0 =C2=
=A0 </span><span style=3D"color:#660">}</span><span style=3D"color:#000"><b=
r><br></span><span style=3D"color:#008">private</span><span style=3D"color:=
#660">:</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span sty=
le=3D"color:#008">char</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">*</span><span style=3D"color:#000"> m_data</span><span styl=
e=3D"color:#660">;</span><span style=3D"color:#000"><br></span><span style=
=3D"color:#660">};</span><span style=3D"color:#000"><br></span></div></code=
></div><br>Here we turn the const qualifier on and off, and it solves the p=
roblem elegantly.</div><div>This qualifier deduction feature can even be ap=
plied to the serialization example.</div><div>I probably need to think how =
it acts with reference qualifiers as well.</div><div><br></div><div>What do=
 you think?</div><div>Eyal.</div></div></blockquote></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/620406e2-5ab9-44cc-9561-b1af054a6404%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/620406e2-5ab9-44cc-9561-b1af054a6404=
%40isocpp.org</a>.<br />

------=_Part_2839_119860002.1470518641538--

------=_Part_2838_2091874903.1470518641536--

.


Author: eyalz800@gmail.com
Date: Sat, 6 Aug 2016 14:28:10 -0700 (PDT)
Raw View
------=_Part_2611_446248038.1470518890711
Content-Type: multipart/alternative;
 boundary="----=_Part_2612_2085673539.1470518890712"

------=_Part_2612_2085673539.1470518890712
Content-Type: text/plain; charset=UTF-8

We can even argue about efficiency, consider an implementation of
optional::operator*:

template <typename T>
class optional
{
public:
    // We deal with all qualifiers with a single overload,
    // even returning an xvalue when able, thus making the code more
efficient.
    auto && operator*() auto &&
    {
        return std::forward<auto>(*this).m_t;
    }

private:
    union {
        char m_dummy;
        T m_t;
    };
};

On Thursday, August 4, 2016 at 9:56:52 PM UTC+3, inkwizyt...@gmail.com
wrote:
>
>
>
> On Thursday, August 4, 2016 at 3:29:39 AM UTC+2, Thiago Macieira wrote:
>>
>> On quarta-feira, 3 de agosto de 2016 15:17:40 PDT eyal...@gmail.com
>> wrote:
>> > One final note: If you didn't notice, the last example can be made even
>> > simpler using return type deduction:
>> > class string
>> > {
>> > public:
>> >     auto c_str() const(auto)
>> >     {
>> >         return m_data;
>> >     }
>> >
>> > private:
>> >     char * m_data;
>> > };
>>
>> This doesn't do what you want. A const object makes the member pointer
>> const,
>> not the pointed data. The above would create a
>>          char * const c_str() const
>>
>> which has cv-qualifiers on a primitive, return type (prvalue). It's
>> ignored and
>> dropped.
>>
>> --
>> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
>>    Software Architect - Intel Open Source Technology Center
>>
>>
> This part could be solved by library solution that could propagate
> constens into pointers:
>
> https://groups.google.com/a/isocpp.org/forum/?fromgroups#!searchin/std-proposals/propagate/std-proposals/NwLIq4d2-oI/Ajj4kyYUGz8J
> I see good synergy between them.
>

--
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/509ec597-a312-4360-bd28-5a9beec98d07%40isocpp.org.

------=_Part_2612_2085673539.1470518890712
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">We can even argue about efficiency, consider an implementa=
tion of optional::operator*:<div><br></div><div><div style=3D"border: 1px s=
olid rgb(187, 187, 187); word-wrap: break-word; background-color: rgb(250, =
250, 250);"><code><span style=3D"color: rgb(0, 0, 136);">template</span><sp=
an style=3D"color: rgb(0, 0, 0);">=C2=A0</span><span style=3D"color: rgb(10=
2, 102, 0);">&lt;</span><span style=3D"color: rgb(0, 0, 136);">typename</sp=
an><span style=3D"color: rgb(0, 0, 0);">=C2=A0T</span><span style=3D"color:=
 rgb(102, 102, 0);">&gt;</span><span style=3D"color: rgb(0, 0, 0);"><br></s=
pan><span style=3D"color: rgb(0, 0, 136);">class</span><span style=3D"color=
: rgb(0, 0, 0);">=C2=A0optional<br></span><span style=3D"color: rgb(102, 10=
2, 0);">{</span><span style=3D"color: rgb(0, 0, 0);"><br></span><span style=
=3D"color: rgb(0, 0, 136);">public</span><span style=3D"color: rgb(102, 102=
, 0);">:</span><span style=3D"color: rgb(0, 0, 0);"><br>=C2=A0 =C2=A0=C2=A0=
</span><span style=3D"color: rgb(136, 0, 0);">// We deal with all qualifier=
s with a single overload,</span><span style=3D"color: rgb(0, 0, 0);"><br>=
=C2=A0 =C2=A0=C2=A0</span><span style=3D"color: rgb(136, 0, 0);">// even re=
turning an xvalue when able, thus=C2=A0</span><span style=3D"color: rgb(136=
, 0, 0);">making the code more efficient.</span><span style=3D"color: rgb(0=
, 0, 0);"><br>=C2=A0 =C2=A0=C2=A0</span><span style=3D"color: rgb(0, 0, 136=
);">auto</span><span style=3D"color: rgb(0, 0, 0);">=C2=A0</span><span styl=
e=3D"color: rgb(102, 102, 0);">&amp;&amp;</span><span style=3D"color: rgb(0=
, 0, 0);">=C2=A0</span><span style=3D"color: rgb(0, 0, 136);">operator</spa=
n><span style=3D"color: rgb(102, 102, 0);">*()</span><span style=3D"color: =
rgb(0, 0, 0);">=C2=A0</span><span style=3D"color: rgb(0, 0, 136);">auto</sp=
an><span style=3D"color: rgb(0, 0, 0);">=C2=A0</span><span style=3D"color: =
rgb(102, 102, 0);">&amp;&amp;</span><span style=3D"color: rgb(0, 0, 0);"><b=
r>=C2=A0 =C2=A0=C2=A0</span><span style=3D"color: rgb(102, 102, 0);">{</spa=
n><span style=3D"color: rgb(0, 0, 0);"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=
=A0</span><span style=3D"color: rgb(0, 0, 136);">return</span><span style=
=3D"color: rgb(0, 0, 0);">=C2=A0std</span><span style=3D"color: rgb(102, 10=
2, 0);">::</span><span style=3D"color: rgb(0, 0, 0);">forward</span><span s=
tyle=3D"color: rgb(0, 136, 0);">&lt;auto&gt;</span><span style=3D"color: rg=
b(102, 102, 0);">(*</span><span style=3D"color: rgb(0, 0, 136);">this</span=
><span style=3D"color: rgb(102, 102, 0);">).</span><span style=3D"color: rg=
b(0, 0, 0);">m_t</span><font color=3D"#008800"><span style=3D"color: rgb(10=
2, 102, 0);"><wbr>;</span></font><span style=3D"color: rgb(0, 0, 0);"><br>=
=C2=A0 =C2=A0=C2=A0</span><span style=3D"color: rgb(102, 102, 0);">}</span>=
<span style=3D"color: rgb(0, 0, 0);"><br><br></span><span style=3D"color: r=
gb(0, 0, 136);">private</span><span style=3D"color: rgb(102, 102, 0);">:</s=
pan></code></div><div style=3D"border: 1px solid rgb(187, 187, 187); word-w=
rap: break-word; background-color: rgb(250, 250, 250);"><code><span style=
=3D"color: rgb(102, 102, 0);">=C2=A0 =C2=A0 union {</span></code></div><div=
 style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; back=
ground-color: rgb(250, 250, 250);"><code><span style=3D"color: rgb(102, 102=
, 0);">=C2=A0 =C2=A0 =C2=A0 =C2=A0 char m_dummy;</span></code></div><div st=
yle=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; backgro=
und-color: rgb(250, 250, 250);"><code><font color=3D"#000000">=C2=A0 =C2=A0=
 =C2=A0 =C2=A0 T</font><span style=3D"color: rgb(0, 0, 0);">=C2=A0m_t</span=
><span style=3D"color: rgb(102, 102, 0);">;</span></code></div><div style=
=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; background=
-color: rgb(250, 250, 250);"><code><font color=3D"#666600">=C2=A0 =C2=A0 };=
<br></font><span style=3D"color: rgb(102, 102, 0);">};</span></code></div><=
/div><br>On Thursday, August 4, 2016 at 9:56:52 PM UTC+3, inkwizyt...@gmail=
..com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left=
: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><b=
r><br>On Thursday, August 4, 2016 at 3:29:39 AM UTC+2, Thiago Macieira wrot=
e:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;bor=
der-left:1px #ccc solid;padding-left:1ex">On quarta-feira, 3 de agosto de 2=
016 15:17:40 PDT <a rel=3D"nofollow">eyal...@gmail.com</a> wrote:
<br>&gt; One final note: If you didn&#39;t notice, the last example can be =
made even=20
<br>&gt; simpler using return type deduction:
<br>&gt; class string
<br>&gt; {
<br>&gt; public:
<br>&gt; =C2=A0 =C2=A0 auto c_str() const(auto)
<br>&gt; =C2=A0 =C2=A0 {
<br>&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 return m_data;
<br>&gt; =C2=A0 =C2=A0 }
<br>&gt;=20
<br>&gt; private:
<br>&gt; =C2=A0 =C2=A0 char * m_data;
<br>&gt; };
<br>
<br>This doesn&#39;t do what you want. A const object makes the member poin=
ter const,=20
<br>not the pointed data. The above would create a
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0char * const c_st=
r() const
<br>
<br>which has cv-qualifiers on a primitive, return type (prvalue). It&#39;s=
 ignored and=20
<br>dropped.
<br>
<br>--=20
<br>Thiago Macieira - thiago (AT) <a href=3D"http://macieira.info" rel=3D"n=
ofollow" target=3D"_blank" onmousedown=3D"this.href=3D&#39;http://www.googl=
e.com/url?q\x3dhttp%3A%2F%2Fmacieira.info\x26sa\x3dD\x26sntz\x3d1\x26usg\x3=
dAFQjCNEswDUBNCNanbu7euhqLn_62FW8ag&#39;;return true;" onclick=3D"this.href=
=3D&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fmacieira.info\x26sa\x3d=
D\x26sntz\x3d1\x26usg\x3dAFQjCNEswDUBNCNanbu7euhqLn_62FW8ag&#39;;return tru=
e;">macieira.info</a> - thiago (AT) <a href=3D"http://kde.org" rel=3D"nofol=
low" target=3D"_blank" onmousedown=3D"this.href=3D&#39;http://www.google.co=
m/url?q\x3dhttp%3A%2F%2Fkde.org\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHGR=
Jdo5_JYG1DowztwAHAKs80XSA&#39;;return true;" onclick=3D"this.href=3D&#39;ht=
tp://www.google.com/url?q\x3dhttp%3A%2F%2Fkde.org\x26sa\x3dD\x26sntz\x3d1\x=
26usg\x3dAFQjCNHGRJdo5_JYG1DowztwAHAKs80XSA&#39;;return true;">kde.org</a>
<br>=C2=A0 =C2=A0Software Architect - Intel Open Source Technology Center
<br>
<br></blockquote><div><br>This part could be solved by library solution tha=
t could propagate constens into pointers:<br><a href=3D"https://groups.goog=
le.com/a/isocpp.org/forum/?fromgroups#!searchin/std-proposals/propagate/std=
-proposals/NwLIq4d2-oI/Ajj4kyYUGz8J" target=3D"_blank" rel=3D"nofollow" onm=
ousedown=3D"this.href=3D&#39;https://groups.google.com/a/isocpp.org/forum/?=
fromgroups#!searchin/std-proposals/propagate/std-proposals/NwLIq4d2-oI/Ajj4=
kyYUGz8J&#39;;return true;" onclick=3D"this.href=3D&#39;https://groups.goog=
le.com/a/isocpp.org/forum/?fromgroups#!searchin/std-proposals/propagate/std=
-proposals/NwLIq4d2-oI/Ajj4kyYUGz8J&#39;;return true;">https://groups.googl=
e.com/a/<wbr>isocpp.org/forum/?fromgroups#!<wbr>searchin/std-proposals/<wbr=
>propagate/std-proposals/<wbr>NwLIq4d2-oI/Ajj4kyYUGz8J</a><br>I see good sy=
nergy between them.<br></div></div></blockquote></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/509ec597-a312-4360-bd28-5a9beec98d07%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/509ec597-a312-4360-bd28-5a9beec98d07=
%40isocpp.org</a>.<br />

------=_Part_2612_2085673539.1470518890712--

------=_Part_2611_446248038.1470518890711--

.