Topic: Covariant accessor functions


Author: David Krauss <potswa@gmail.com>
Date: Sun, 19 Jul 2015 09:14:14 +0800
Raw View
--Apple-Mail=_F8D2F780-791E-4F46-A296-8FA70B1CFE4E
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8

What does everyone think of a syntax to eliminate accessor overloading boil=
erplate? This extension is designed to safely replace this:

    prop member;
public:
    prop & get_property() &
        { return member; }
    prop const & get_property() const &
        { return member; }
    prop && get_property() &&
        { return std::move( member ); }

with this:

    prop member;
public:
    prop & get_property() export(const) &
        { return member; }

It should also work (safely!) in any similar situation, given appropriate s=
yntax variations.

    T member; // may be a reference
public:
    T & get_property() export(const) &
        { return member; }

    T const & get_const_property() export const &
        { return member; } // Read-only access, perfect rvalue treatment

    T const & get_const_property2() export(const) & // Idiomatic, useless b=
ut harmless
        { return member; }

    auto begin() export(const) // Covariant-ish in const, not value categor=
y.
        { return iterator_type< decltype(*this) >( begin_pointer ); }

    T & operator [] ( index_type x ) export & // Covariant in value categor=
y, but not const.
        { return * insert( value_type{ x } )->first; }


(Background: this is part of a larger proposal to let export indicate that =
a function parameter owns the return value, or for constructors, the constr=
ucted object. It was already presented as N4221.)

Feedback would be much appreciated as I actually plan to implement this bef=
ore the next meeting. Thanks!
-----

Covariant accessors
A lifetime-qualified implicit object parameter indicates that a member func=
tion=E2=80=99s return value references data owned by its object. If the obj=
ect is expiring, then the data certainly is as well. The same property typi=
cally applies, via const, to modifiability. The reference types of the impl=
icit object argument and the return value are covariant because they concep=
tually refer to parts of the same item. This is also the idea expressed by =
export, so export implements such covariance.

Rvalue accessors
When an export specifier applies to an implicit parameter with lvalue refer=
ence qualification, and the return type is declared with the & qualifier, a=
n additional rvalue accessor overload may be implicitly declared with both =
& punctuators transformed to &&. The specific preconditions are:

The declarator D1 contained in the function declarator as per [dcl.fct] is =
a declarator-id. The declaration is of a member function and not something =
like a pointer to a function.
The ref-qualifier of the function declarator is &.
No member function is explicitly declared in the class with a ref-qualifier=
 of &&, and the same name, parameter list, and cv-qualifier-seq.
The implicit object parameter is lifetime-qualified and its lifetime specif=
ier is not export(auto).
The function declarator appears as D1 in a declarator of the form
    & attribute-specifier-seqoptD1
according to [dcl.ref], i.e. the function return type is immediately declar=
ed as a reference.
If the reference declarator immediately enclosing the function declarator i=
s the complete declarator, the decl-specifier-seq specifies a non-reference=
 type or a dependent type .
A specialization of an implicitly-declared rvalue accessor template partici=
pates in overload resolution only if it satisfies precondition #6, which fo=
rbids reference collapsing.

If an implicitly-defined rvalue accessor or const accessor (see below) woul=
d override a virtual function, the program is ill-formed.

The user may also declare an rvalue accessor as explicitly defaulted. This =
is allowed even if the preconditions relating to the return type (#5-6) are=
 unmet for the original function, and precondition #4 is relaxed so that an=
y lifetime specifier is sufficient, even export(false). Conversely, =E2=80=
=9C=3D default=E2=80=9D is allowed for any function declaration mentioning =
=E2=80=9C&& export=E2=80=9D given a corresponding =E2=80=9C& export=E2=80=
=9D overload. The return type need not match that of the preempted implicit=
 declaration. Such a template may be called even if the decl-specifier-seq =
specifies a reference type. (Note, if the return type is as-implicit and th=
e dependent type specifies a reference, the function will emulate access to=
 a nonstatic member reference.)

An implicitly-defined rvalue accessor acts as a forwarding call wrapper to =
the original lvalue-qualified function. If the implicit object parameter of=
 the original function is lifetime-qualified, and the return type of the rv=
alue accessor is not an lvalue reference type, the result is treated as an =
xvalue. Otherwise, the result initializes the return value normally.

Const accessors
The export(const) specifier indicates to use a common function body for con=
st and non-const accessor overloads, and to generate a covariant return typ=
e. It may only be used in a member declaration meeting these constraints:

The declarator D1 contained in the function declarator as per [dcl.fct] is =
a declarator-id, i.e. export(const) can only decorate a member function.
The cv-qualifier-seq of the declarator does not include const.
No member function is explicitly declared in the class with the same ref-qu=
alifier, name, and parameter list, but with an added const cv-qualifier.
The return type of the member function is a reference or pointer type, or t=
he decl-specifier-seq includes an auto or decltype(auto) type-specifier.
If a specialization of a template declared export(const) fails constraint #=
4, the program is ill-formed.

A function declaration with export(const) is treated as two explicit declar=
ations (or definitions) differing in that one includes const in its cv-qual=
ifier-seq, and one does not. Both use the export lifetime specifier. The re=
turn type of the non-const function is as declared, and the declared return=
 type of the const overload is modified as follows:

If the declarator immediately enclosing the function declarator is a pointe=
r or reference declarator, its modified type T is replaced with T const. (T=
his has no effect if T is a reference type.)
Otherwise, if the return type is a pointer type T* or reference type T& or =
T&&, its referent T is replaced with T const.
Otherwise, by logical deduction, the declared return type must be auto or d=
ecltype(auto), and it is not modified.
There is no requirement that the unmodified return type lack const qualific=
ation. If it is already qualified, there is no covariance.

A function declaration generated by export(const) may generate an rvalue ac=
cessor, or may explicitly declare an rvalue accessor.


Sorry about the wonky section numbering; my word processor lost it in the H=
TML conversion. The original latest draft is available at http://bit.ly/gen=
life <http://bit.ly/genlife> (PDF), see =C2=A74.3.

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--Apple-Mail=_F8D2F780-791E-4F46-A296-8FA70B1CFE4E
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><div class=3D"">Wh=
at does everyone think of a syntax to eliminate accessor overloading boiler=
plate? This extension is designed to safely replace this:</div><div class=
=3D""><br class=3D""></div><div class=3D""><font face=3D"Courier" class=3D"=
">&nbsp; &nbsp; prop member;</font></div><div class=3D""><font face=3D"Cour=
ier" class=3D"">public:</font></div><div class=3D""><font face=3D"Courier" =
class=3D"">&nbsp; &nbsp; prop &amp; get_property() &amp;</font></div><div c=
lass=3D""><font face=3D"Courier" class=3D"">&nbsp; &nbsp; &nbsp; &nbsp; { r=
eturn member; }</font></div><div class=3D""><font face=3D"Courier" class=3D=
"">&nbsp; &nbsp;&nbsp;</font><span style=3D"font-family: Courier;" class=3D=
"">prop</span><font face=3D"Courier" class=3D"">&nbsp;const &amp; get_prope=
rty() const &amp;</font></div><div class=3D""><font face=3D"Courier" class=
=3D"">&nbsp; &nbsp; &nbsp; &nbsp; { return member; }</font></div><div class=
=3D""><font face=3D"Courier" class=3D"">&nbsp; &nbsp;&nbsp;</font><span sty=
le=3D"font-family: Courier;" class=3D"">prop</span><font face=3D"Courier" c=
lass=3D"">&nbsp;&amp;&amp; get_property() &amp;&amp;</font></div><div class=
=3D""><div class=3D""><font face=3D"Courier" class=3D"">&nbsp; &nbsp; &nbsp=
; &nbsp; { return std::move( member ); }</font></div></div><div class=3D"">=
<br class=3D""></div><div class=3D"">with this:</div><div class=3D""><br cl=
ass=3D""></div><div class=3D""><font face=3D"Courier" class=3D"">&nbsp; &nb=
sp; prop member;</font></div><div class=3D""><font face=3D"Courier" class=
=3D"">public:</font></div><div class=3D""><font face=3D"Courier" class=3D""=
>&nbsp; &nbsp;&nbsp;</font><span style=3D"font-family: Courier;" class=3D""=
>prop</span><font face=3D"Courier" class=3D"">&nbsp;&amp; get_property() ex=
port(const) &amp;</font></div><div class=3D""><font face=3D"Courier" class=
=3D"">&nbsp; &nbsp; &nbsp; &nbsp; { return member; }</font></div><div class=
=3D""><br class=3D""></div><div class=3D"">It should also work (safely!) in=
 any similar situation, given appropriate syntax variations.</div><div clas=
s=3D""><br class=3D""></div><div class=3D""><font face=3D"Courier" class=3D=
"">&nbsp; &nbsp; T member; // may be a reference</font></div><div class=3D"=
"><font face=3D"Courier" class=3D"">public:</font></div><div class=3D""><fo=
nt face=3D"Courier" class=3D"">&nbsp;&nbsp; &nbsp;T &amp; get_property() ex=
port(const) &amp;</font></div><div class=3D""><font face=3D"Courier" class=
=3D"">&nbsp; &nbsp; &nbsp; &nbsp; { return member; }</font></div><div class=
=3D""><font face=3D"Courier" class=3D""><br class=3D""></font></div><div cl=
ass=3D""><font face=3D"Courier" class=3D"">&nbsp; &nbsp; T const &amp; get_=
const_property() export const &amp;</font></div><div class=3D""><font face=
=3D"Courier" class=3D"">&nbsp; &nbsp; &nbsp; &nbsp; { return member; } // R=
ead-only access, perfect rvalue treatment</font></div><div class=3D""><div =
class=3D""><font face=3D"Courier" class=3D""><br class=3D""></font></div><d=
iv class=3D""><font face=3D"Courier" class=3D"">&nbsp; &nbsp; T const &amp;=
 get_const_property2() export(const) &amp; // Idiomatic, useless but harmle=
ss</font></div><div class=3D""><font face=3D"Courier" class=3D"">&nbsp; &nb=
sp; &nbsp; &nbsp; { return member; }</font></div></div><div class=3D""><fon=
t face=3D"Courier" class=3D""><br class=3D""></font></div><div class=3D""><=
font face=3D"Courier" class=3D"">&nbsp; &nbsp; auto begin() export(const)</=
font><span style=3D"font-family: Courier;" class=3D"">&nbsp;</span><span st=
yle=3D"font-family: Courier;" class=3D"">// Covariant-ish in const, not val=
ue category.</span></div><div class=3D""><font face=3D"Courier" class=3D"">=
&nbsp; &nbsp; &nbsp; &nbsp; { return iterator_type&lt; decltype(*this) &gt;=
( begin_pointer ); }</font></div><div class=3D""><font face=3D"Courier" cla=
ss=3D""><br class=3D""></font></div><div class=3D""><font face=3D"Courier" =
class=3D"">&nbsp; &nbsp; T &amp; operator [] ( index_type x ) export &amp; =
// Covariant in value category, but not const.</font></div><div class=3D"">=
<font face=3D"Courier" class=3D"">&nbsp; &nbsp; &nbsp; &nbsp; { return * in=
sert( value_type{ x } )-&gt;first; }</font></div><div class=3D""><br class=
=3D""></div><div class=3D""><br class=3D""></div><div class=3D"">(Backgroun=
d: this is part of a larger proposal to let <font face=3D"Courier" class=3D=
"">export</font> indicate that a function parameter owns the return value, =
or for constructors, the constructed object. It was already presented as N4=
221.)</div><div class=3D""><br class=3D""></div><div class=3D"">Feedback wo=
uld be much appreciated as I actually plan to implement this before the nex=
t meeting. Thanks!</div><div class=3D"">-----</div><div class=3D""><br clas=
s=3D""></div><ol class=3D""><li style=3D"margin: 0px 0px 8px; font-size: 14=
px; font-family: Times; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-te=
xt-stroke-width: initial;" class=3D""><span style=3D"font-size: 12px; font-=
family: Helvetica;" class=3D""></span>Covariant accessors</li>

</ol><p style=3D"margin: 0px 0px 16px; font-family: Times; -webkit-text-str=
oke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=3D"">A =
lifetime-qualified implicit object parameter indicates that a member functi=
on=E2=80=99s return value references data owned by its object. If the objec=
t is expiring, then the data certainly is as well. The same property typica=
lly applies, via <span style=3D"font-family: Courier;" class=3D"">const</sp=
an>, to modifiability. The reference types of the implicit object argument =
and the return value are covariant because they conceptually refer to parts=
 of the same item. This is also the idea expressed by <span style=3D"font-f=
amily: Courier;" class=3D"">export</span>, so <span style=3D"font-family: C=
ourier;" class=3D"">export</span> implements such covariance.</p>
<ol class=3D"">


<li style=3D"margin: 0px 0px 8px; font-size: 13px; font-family: Times; -web=
kit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" c=
lass=3D""><span style=3D"font-size: 12px; font-family: Helvetica;" class=3D=
""></span>Rvalue accessors</li>


</ol><p style=3D"margin: 0px 0px 6px; font-family: Times; -webkit-text-stro=
ke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=3D"">Whe=
n an <span style=3D"font-family: Courier;" class=3D"">export</span> specifi=
er applies to an implicit parameter with lvalue reference qualification, an=
d the return type is declared with the <span style=3D"font-family: Courier;=
" class=3D"">&amp;</span> qualifier, an additional <i class=3D"">rvalue acc=
essor</i> overload may be implicitly declared with both <span style=3D"font=
-family: Courier;" class=3D"">&amp;</span> punctuators transformed to <span=
 style=3D"font-family: Courier;" class=3D"">&amp;&amp;</span>. The specific=
 preconditions are:</p>
<ol class=3D"">
<li style=3D"margin: 0px 0px 6px; font-family: Times; -webkit-text-stroke-c=
olor: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=3D""><span s=
tyle=3D"font-family: Helvetica;" class=3D""></span>The declarator <span sty=
le=3D"font-family: Courier;" class=3D"">D1</span> contained in the function=
 declarator as per [dcl.fct] is a <i class=3D"">declarator-id</i>. The decl=
aration is of a member function and not something like a pointer to a funct=
ion.</li>
<li style=3D"margin: 0px 0px 6px; font-family: Times; -webkit-text-stroke-c=
olor: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=3D""><span s=
tyle=3D"font-family: Helvetica;" class=3D""></span>The <i class=3D"">ref-qu=
alifier</i> of the function declarator is <span style=3D"font-family: Couri=
er;" class=3D"">&amp;</span>.</li>
<li style=3D"margin: 0px 0px 6px; font-family: Times; -webkit-text-stroke-c=
olor: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=3D""><span s=
tyle=3D"font-family: Helvetica;" class=3D""></span>No member function is ex=
plicitly declared in the class with a <i class=3D"">ref-qualifier</i> of <s=
pan style=3D"font-family: Courier;" class=3D"">&amp;&amp;</span>, and the s=
ame name, parameter list, and <i class=3D"">cv-qualifier-seq</i>.</li>
<li style=3D"margin: 0px 0px 6px; font-family: Times; -webkit-text-stroke-c=
olor: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=3D""><span s=
tyle=3D"font-family: Helvetica;" class=3D""></span>The implicit object para=
meter is lifetime-qualified and its lifetime specifier is not <span style=
=3D"font-family: Courier;" class=3D"">export(auto)</span>.</li>
<li style=3D"margin: 0px 0px 6px; font-family: Times; -webkit-text-stroke-c=
olor: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=3D""><span s=
tyle=3D"font-family: Helvetica;" class=3D""></span>The function declarator =
appears as <span style=3D"font-family: Courier;" class=3D"">D1</span> in a =
declarator of the form<br class=3D"">
&nbsp; &nbsp; <span style=3D"font-family: Courier;" class=3D"">&amp;</span>=
 <i class=3D"">attribute-specifier-seq</i><span style=3D"font-size: 8px;" c=
lass=3D""><i class=3D""><sub class=3D"">opt</sub></i></span><span style=3D"=
font-family: Courier;" class=3D"">D1</span><br class=3D"">
according to [dcl.ref], i.e. the function return type is immediately declar=
ed as a reference.</li>
<li style=3D"margin: 0px 0px 6px; font-family: Times; -webkit-text-stroke-c=
olor: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=3D""><span s=
tyle=3D"font-family: Helvetica;" class=3D""></span>If the reference declara=
tor immediately enclosing the function declarator is the complete declarato=
r, the <i class=3D"">decl-specifier-seq</i> specifies a non-reference type =
or a dependent type <span style=3D"font-size: 8px;" class=3D""><sup class=
=3D""></sup></span>.</li>
</ol><p style=3D"margin: 0px 0px 6px; font-family: Times; -webkit-text-stro=
ke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=3D"">A s=
pecialization of an implicitly-declared rvalue accessor template participat=
es in overload resolution only if it satisfies precondition #6, which forbi=
ds reference collapsing.</p><p style=3D"margin: 0px 0px 6px; font-family: T=
imes; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: i=
nitial;" class=3D"">If an implicitly-defined rvalue accessor or const acces=
sor (see below) would override a virtual function, the program is ill-forme=
d.</p><p style=3D"margin: 0px 0px 6px; font-family: Times; -webkit-text-str=
oke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=3D"">Th=
e user may also declare an rvalue accessor as explicitly defaulted. This is=
 allowed even if the preconditions relating to the return type (#5-6) are u=
nmet for the original function, and precondition #4 is relaxed so that any =
lifetime specifier is sufficient, even <span style=3D"font-family: Courier;=
" class=3D"">export(false)</span>. Conversely, =E2=80=9C<span style=3D"font=
-family: Courier;" class=3D"">=3D default</span>=E2=80=9D is allowed for an=
y function declaration mentioning =E2=80=9C<span style=3D"font-family: Cour=
ier;" class=3D"">&amp;&amp; export</span>=E2=80=9D given a corresponding =
=E2=80=9C<span style=3D"font-family: Courier;" class=3D"">&amp; export</spa=
n>=E2=80=9D overload. The return type need not match that of the preempted =
implicit declaration. Such a template may be called even if the <i class=3D=
"">decl-specifier-seq</i> specifies a reference type. (Note, if the return =
type is as-implicit and the dependent type specifies a reference, the funct=
ion will emulate access to a nonstatic member reference.)</p><p style=3D"ma=
rgin: 0px 0px 16px; font-family: Times; -webkit-text-stroke-color: rgb(0, 0=
, 0); -webkit-text-stroke-width: initial;" class=3D"">An implicitly-defined=
 rvalue accessor acts as a forwarding call wrapper to the original lvalue-q=
ualified function. If the implicit object parameter of the original functio=
n is lifetime-qualified, and the return type of the rvalue accessor is not =
an lvalue reference type, the result is treated as an xvalue. Otherwise, th=
e result initializes the return value normally.</p>
<ol class=3D"">


<li style=3D"margin: 0px 0px 8px; font-size: 13px; font-family: Times; -web=
kit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" c=
lass=3D""><span style=3D"font-size: 12px; font-family: Helvetica;" class=3D=
""></span>Const accessors</li>


</ol><p style=3D"margin: 0px 0px 6px; font-family: Times; -webkit-text-stro=
ke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=3D"">The=
 <span style=3D"font-family: Courier;" class=3D"">export(const)</span> spec=
ifier indicates to use a common function body for <span style=3D"font-famil=
y: Courier;" class=3D"">const</span> and non-<span style=3D"font-family: Co=
urier;" class=3D"">const</span> accessor overloads, and to generate a covar=
iant return type. It may only be used in a member declaration meeting these=
 constraints:</p>
<ol class=3D"">
<li style=3D"margin: 0px 0px 6px; font-family: Times; -webkit-text-stroke-c=
olor: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=3D""><span s=
tyle=3D"font-family: Helvetica;" class=3D""></span>The declarator <span sty=
le=3D"font-family: Courier;" class=3D"">D1</span> contained in the function=
 declarator as per [dcl.fct] is a <i class=3D"">declarator-id</i>, i.e. <sp=
an style=3D"font-family: Courier;" class=3D"">export(const)</span> can only=
 decorate a member function.</li>
<li style=3D"margin: 0px 0px 6px; font-family: Times; -webkit-text-stroke-c=
olor: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=3D""><span s=
tyle=3D"font-family: Helvetica;" class=3D""></span>The <i class=3D"">cv-qua=
lifier-seq</i> of the declarator does not include <span style=3D"font-famil=
y: Courier;" class=3D"">const</span>.</li>
<li style=3D"margin: 0px 0px 6px; font-family: Times; -webkit-text-stroke-c=
olor: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=3D""><span s=
tyle=3D"font-family: Helvetica;" class=3D""></span>No member function is ex=
plicitly declared in the class with the same <i class=3D"">ref-qualifier</i=
>, name, and parameter list, but with an added <span style=3D"font-family: =
Courier;" class=3D"">const</span> <i class=3D"">cv-qualifier</i>.</li>
<li style=3D"margin: 0px 0px 6px; font-family: Times; -webkit-text-stroke-c=
olor: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=3D""><span s=
tyle=3D"font-family: Helvetica;" class=3D""></span>The return type of the m=
ember function is a reference or pointer type, or the <i class=3D"">decl-sp=
ecifier-seq</i> includes an <span style=3D"font-family: Courier;" class=3D"=
">auto</span> or <span style=3D"font-family: Courier;" class=3D"">decltype(=
auto)</span> <i class=3D"">type-specifier</i>.</li>
</ol><p style=3D"margin: 0px 0px 6px; font-family: Times; -webkit-text-stro=
ke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=3D"">If =
a specialization of a template declared <span style=3D"font-family: Courier=
;" class=3D"">export(const)</span> fails constraint #4, the program is ill-=
formed.</p><p style=3D"margin: 0px 0px 6px; font-family: Times; -webkit-tex=
t-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=3D=
"">A function declaration with <span style=3D"font-family: Courier;" class=
=3D"">export(const)</span> is treated as two explicit declarations (or defi=
nitions) differing in that one includes <span style=3D"font-family: Courier=
;" class=3D"">const</span> in its <i class=3D"">cv-qualifier-seq</i>, and o=
ne does not. Both use the <span style=3D"font-family: Courier;" class=3D"">=
export</span> lifetime specifier. The return type of the non-<span style=3D=
"font-family: Courier;" class=3D"">const</span> function is as declared, an=
d the declared return type of the <span style=3D"font-family: Courier;" cla=
ss=3D"">const</span> overload is modified as follows:</p>
<ol class=3D"">
<li style=3D"margin: 0px 0px 6px; font-family: Times; -webkit-text-stroke-c=
olor: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=3D""><span s=
tyle=3D"font-family: Helvetica;" class=3D""></span>If the declarator immedi=
ately enclosing the function declarator is a pointer or reference declarato=
r, its modified type <span style=3D"font-family: Courier;" class=3D"">T</sp=
an> is replaced with <span style=3D"font-family: Courier;" class=3D"">T con=
st</span>. (This has no effect if <span style=3D"font-family: Courier;" cla=
ss=3D"">T</span> is a reference type.)</li>
<li style=3D"margin: 0px 0px 6px; font-family: Times; -webkit-text-stroke-c=
olor: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=3D""><span s=
tyle=3D"font-family: Helvetica;" class=3D""></span>Otherwise, if the return=
 type is a pointer type <span style=3D"font-family: Courier;" class=3D"">T*=
</span> or reference type <span style=3D"font-family: Courier;" class=3D"">=
T&amp;</span> or <span style=3D"font-family: Courier;" class=3D"">T&amp;&am=
p;</span>, its referent <span style=3D"font-family: Courier;" class=3D"">T<=
/span> is replaced with <span style=3D"font-family: Courier;" class=3D"">T =
const</span>.</li>
<li style=3D"margin: 0px 0px 6px; font-family: Times; -webkit-text-stroke-c=
olor: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=3D""><span s=
tyle=3D"font-family: Helvetica;" class=3D""></span>Otherwise, by logical de=
duction, the declared return type must be <span style=3D"font-family: Couri=
er;" class=3D"">auto</span> or <span style=3D"font-family: Courier;" class=
=3D"">decltype(auto)</span>, and it is not modified.</li>
</ol><p style=3D"margin: 0px 0px 6px; font-family: Times; -webkit-text-stro=
ke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;" class=3D"">The=
re is no requirement that the unmodified return type lack <span style=3D"fo=
nt-family: Courier;" class=3D"">const</span> qualification. If it is alread=
y qualified, there is no covariance.</p><div class=3D""><p style=3D"margin:=
 0px 0px 16px; font-family: Times; -webkit-text-stroke-color: rgb(0, 0, 0);=
 -webkit-text-stroke-width: initial;" class=3D"">A function declaration gen=
erated by <span style=3D"font-family: Courier;" class=3D"">export(const)</s=
pan> may generate an rvalue accessor, or may explicitly declare an rvalue a=
ccessor.</p></div><div class=3D""><br class=3D""></div><div class=3D""><div=
 class=3D"">Sorry about the wonky section numbering; my word processor lost=
 it in the HTML conversion. The original latest draft is available at&nbsp;=
<a href=3D"http://bit.ly/genlife" class=3D"">http://bit.ly/genlife</a>&nbsp=
;(PDF), see =C2=A74.3.</div></div><div class=3D""><br class=3D""></div></bo=
dy></html>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--Apple-Mail=_F8D2F780-791E-4F46-A296-8FA70B1CFE4E--

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Sun, 19 Jul 2015 04:21:06 +0300
Raw View
On 19 July 2015 at 04:14, David Krauss <potswa@gmail.com> wrote:
> What does everyone think of a syntax to eliminate accessor overloading
> boilerplate? This extension is designed to safely replace this:

Why is it export(const) and not const(auto)?

--

---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: David Krauss <potswa@gmail.com>
Date: Sun, 19 Jul 2015 09:41:51 +0800
Raw View
--Apple-Mail=_7525CD90-F8EF-48FC-9300-320D0BAA75D6
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8


> On 2015=E2=80=9307=E2=80=9319, at 9:21 AM, Ville Voutilainen <ville.vouti=
lainen@gmail.com> wrote:
>=20
> On 19 July 2015 at 04:14, David Krauss <potswa@gmail.com> wrote:
>> What does everyone think of a syntax to eliminate accessor overloading
>> boilerplate? This extension is designed to safely replace this:
>=20
> Why is it export(const) and not const(auto)?

It=E2=80=99s going to be based on the export keyword, which indicates owner=
ship of the function result. Covariance can be deduced from ownership, but =
ownership can=E2=80=99t be deduced from covariance, at least not with as cl=
ear a rationale. Const-covariance without ownership doesn=E2=80=99t happen =
so far as I=E2=80=99m aware, but I=E2=80=99d like to know of any such cases=
..

Perhaps auto(const) could be equivalent to export(const) but without the co=
nnotation that it=E2=80=99s an accessor. That would be a small slice of the=
 proposal, but you=E2=80=99d still have to address value category.

const(auto) suggests that const-ness will be deduced once for the function,=
 whereas actually the entire declaration is replicated. Actually the main p=
roblem I see with the current draft syntax is that replication isn=E2=80=99=
t obvious enough.

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--Apple-Mail=_7525CD90-F8EF-48FC-9300-320D0BAA75D6
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9307=
=E2=80=9319, at 9:21 AM, Ville Voutilainen &lt;<a href=3D"mailto:ville.vout=
ilainen@gmail.com" class=3D"">ville.voutilainen@gmail.com</a>&gt; wrote:</d=
iv><br class=3D"Apple-interchange-newline"><div class=3D"">On 19 July 2015 =
at 04:14, David Krauss &lt;<a href=3D"mailto:potswa@gmail.com" class=3D"">p=
otswa@gmail.com</a>&gt; wrote:<br class=3D""><blockquote type=3D"cite" clas=
s=3D"">What does everyone think of a syntax to eliminate accessor overloadi=
ng<br class=3D"">boilerplate? This extension is designed to safely replace =
this:<br class=3D""></blockquote><br class=3D"">Why is it export(const) and=
 not const(auto)?<br class=3D""></div></blockquote><div><br class=3D""></di=
v><div>It=E2=80=99s going to be based on the <font face=3D"Courier" class=
=3D"">export</font> keyword, which indicates ownership of the function resu=
lt. Covariance can be deduced from ownership, but ownership can=E2=80=99t b=
e deduced from covariance, at least not with as clear a rationale. Const-co=
variance without ownership doesn=E2=80=99t happen so far as I=E2=80=99m awa=
re, but I=E2=80=99d like to know of any such cases.</div><div><br class=3D"=
"></div><div><div class=3D"">Perhaps&nbsp;<font face=3D"Courier" class=3D""=
>auto(const)</font>&nbsp;could be equivalent to&nbsp;<font face=3D"Courier"=
 class=3D"">export(const)</font>&nbsp;but without the connotation that it=
=E2=80=99s an accessor. That would be a small slice of the proposal, but yo=
u=E2=80=99d still have to address value category.</div><div class=3D""><br =
class=3D""></div></div><div><font face=3D"Courier" class=3D"">const(auto)</=
font> suggests that const-ness will be deduced once for the function, where=
as actually the entire declaration is replicated. Actually the main problem=
 I see with the current draft syntax is that replication isn=E2=80=99t obvi=
ous enough.</div></div><div class=3D""><br class=3D""></div></body></html>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--Apple-Mail=_7525CD90-F8EF-48FC-9300-320D0BAA75D6--

.


Author: David Krauss <potswa@gmail.com>
Date: Sun, 19 Jul 2015 10:58:35 +0800
Raw View
--Apple-Mail=_B9372A05-5D73-4523-85F4-5C66936E7C33
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8


> On 2015=E2=80=9307=E2=80=9319, at 9:41 AM, David Krauss <potswa@gmail.com=
> wrote:
>=20
> Perhaps auto(const) could be equivalent to export(const) but without the =
connotation that it=E2=80=99s an accessor. That would be a small slice of t=
he proposal, but you=E2=80=99d still have to address value category.
>=20
> const(auto) suggests that const-ness will be deduced once for the functio=
n, whereas actually the entire declaration is replicated. Actually the main=
 problem I see with the current draft syntax is that replication isn=E2=80=
=99t obvious enough.

Idea! Use square brackets.

So my proposal becomes:

    foo_t & get_foo() export [const] &

Remove export and it still looks reasonable:

    foo_t & get_foo() [const]

However, awareness of ownership is still a more appropriate solution than s=
yntactic sugar, so I don=E2=80=99t see a good reason to propose the latter.

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--Apple-Mail=_B9372A05-5D73-4523-85F4-5C66936E7C33
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9307=
=E2=80=9319, at 9:41 AM, David Krauss &lt;<a href=3D"mailto:potswa@gmail.co=
m" class=3D"">potswa@gmail.com</a>&gt; wrote:</div><br class=3D"Apple-inter=
change-newline"><div class=3D""><div style=3D"font-family: Helvetica; font-=
size: 12px; font-style: normal; font-variant: normal; font-weight: normal; =
letter-spacing: normal; line-height: normal; orphans: auto; text-align: sta=
rt; text-indent: 0px; text-transform: none; white-space: normal; widows: au=
to; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=3D""><div cla=
ss=3D"">Perhaps&nbsp;<font face=3D"Courier" class=3D"">auto(const)</font>&n=
bsp;could be equivalent to&nbsp;<font face=3D"Courier" class=3D"">export(co=
nst)</font>&nbsp;but without the connotation that it=E2=80=99s an accessor.=
 That would be a small slice of the proposal, but you=E2=80=99d still have =
to address value category.</div><div class=3D""><br class=3D""></div></div>=
<div style=3D"font-family: Helvetica; font-size: 12px; font-style: normal; =
font-variant: normal; font-weight: normal; letter-spacing: normal; line-hei=
ght: normal; orphans: auto; text-align: start; text-indent: 0px; text-trans=
form: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-t=
ext-stroke-width: 0px;" class=3D""><font face=3D"Courier" class=3D"">const(=
auto)</font><span class=3D"Apple-converted-space">&nbsp;</span>suggests tha=
t const-ness will be deduced once for the function, whereas actually the en=
tire declaration is replicated. Actually the main problem I see with the cu=
rrent draft syntax is that replication isn=E2=80=99t obvious enough.</div><=
/div></blockquote></div><br class=3D""><div class=3D"">Idea! Use square bra=
ckets.</div><div class=3D""><br class=3D""></div><div class=3D"">So my prop=
osal becomes:</div><div class=3D""><font face=3D"Courier" class=3D""><br cl=
ass=3D""></font></div><div class=3D""><font face=3D"Courier" class=3D"">&nb=
sp; &nbsp; foo_t &amp; get_foo() export [const] &amp;</font></div><div clas=
s=3D""><br class=3D""></div><div class=3D"">Remove&nbsp;<font face=3D"Couri=
er" class=3D"">export</font>&nbsp;and it still looks reasonable:</div><div =
class=3D""><br class=3D""></div><div class=3D""><div class=3D""><font face=
=3D"Courier" class=3D"">&nbsp; &nbsp; foo_t &amp; get_foo() [const]</font><=
/div></div><div class=3D""><br class=3D""></div><div class=3D"">However, aw=
areness of ownership is still a more appropriate solution than syntactic su=
gar, so I don=E2=80=99t see a good reason to propose the latter.</div><div =
class=3D""><br class=3D""></div></body></html>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--Apple-Mail=_B9372A05-5D73-4523-85F4-5C66936E7C33--

.