Topic: Generalized lifetime extension: call for examples


Author: David Krauss <potswa@gmail.com>
Date: Thu, 2 Oct 2014 17:44:13 +0800
Raw View
--Apple-Mail=_56751B44-03EF-4257-B83E-24BBA6E07539
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1

My next proposal is my most ambitious for Urbana. I think I've got most of =
the specification down, but I really need a variety of examples of its use,=
 and a sense of real-world cases to be sure the spec is right.

It's designed to solve dangling references to temporaries by allowing poten=
tially any temporary to get lifetime extension to the remainder of its scop=
e. So, if you have an interesting dangling reference case, and you can form=
at the code suitably for the printed page, please reply.

Basic example:

template< typename object >
object const &
id( object const & * o ) // * indicates that the result refers into the par=
ameter.
    { return o; }

auto && x =3D id( foo{} ); // Not a dangling reference.

Example with an accessor:

class haz_int {
    int haz;
public:
    int const & can_haz() * // * indicates that result refers into this
        { return haz; }
};

auto && y =3D haz_int{}.can_haz(); // Not dangling.

The magic does not extend to attempting to return a prvalue expression by r=
eference; I don't need examples like this:

auto && should_decltypeauto() {
    return 5; // Still broken. Return by value instead.
}

The recently bumped "as_const" thread has a great example, but it needs a b=
rief write-up:
 std::vector<int> vec;
 for (int val : vec | boost::adaptors::reversed
                    | boost::adaptors::uniqued) {
   // Do stuff with val
 }

For that matter, this example comes from EWG 120 and I should really cite a=
ny official issue tickets that may be touched, including LWG, EWG, and CWG.=
 Help with that will be much appreciated too.

Of course, any example or reference submitters will be credited in the pape=
r. Other than that, I turn 30 on the fourth, so consider this my birthday p=
resent :) .

Abstract:
---
This proposal introduces a model to describe the connection between a value=
 and the object or objects needed to represent it. This enables a generaliz=
ation of lifetime extension, applicable to glvalue accessor function calls =
through some new function parameter syntax. The current lifetime extension =
behavior is also more elegantly described, and the "temporary expression" c=
ontroversy is resolved. The model may also enable strong copy elision guara=
ntees.
---

Link: http://bit.ly/1vzN57X

--=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=_56751B44-03EF-4257-B83E-24BBA6E07539
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=ISO-8859-1

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dwindows-1252"><meta http-equiv=3D"Content-Type" content=3D"text/html cha=
rset=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; -webkit-n=
bsp-mode: space; -webkit-line-break: after-white-space;"><div>My next propo=
sal is my most ambitious for Urbana. I think I&rsquo;ve got most of the spe=
cification down, but I really need a variety of examples of its use, and a =
sense of real-world cases to be sure the spec is right.</div><div><br></div=
><div>It&rsquo;s designed to solve dangling references to temporaries by al=
lowing potentially any temporary to get lifetime extension to the remainder=
 of its scope. So, if you have an interesting dangling reference case, and =
you can format the code suitably for the printed page, please reply.</div><=
div><br></div><div>Basic example:</div><div><br></div><div><font face=3D"Co=
urier">template&lt; typename object &gt;</font></div><div><font face=3D"Cou=
rier">object const &amp;</font></div><div><font face=3D"Courier">id( object=
 const &amp; * o ) // * indicates that the result refers into the parameter=
..</font></div><div><font face=3D"Courier">&nbsp; &nbsp; { return o; }</font=
></div><div><font face=3D"Courier"><br></font></div><div><span style=3D"fon=
t-family: Courier;">auto &amp;&amp; x =3D id( foo{} ); // Not a dangling re=
ference.</span></div><div><br></div><div>Example with an accessor:</div><di=
v><br></div><div><font face=3D"Courier">class haz_int {</font></div><div><f=
ont face=3D"Courier">&nbsp; &nbsp; int haz;</font></div><div><font face=3D"=
Courier">public:</font></div><div><font face=3D"Courier">&nbsp; &nbsp; int =
const &amp;&nbsp;can_haz() * // * indicates that result refers into this</f=
ont></div><div><font face=3D"Courier">&nbsp; &nbsp; &nbsp; &nbsp; { return =
haz; }</font></div><div><font face=3D"Courier">};</font></div><div><font fa=
ce=3D"Courier"><br></font></div><div><font face=3D"Courier">auto &amp;&amp;=
 y =3D haz_int{}.can_haz(); // Not dangling.</font></div><div><br></div><di=
v>The magic does not extend to attempting to return a prvalue expression by=
 reference; I don&rsquo;t need examples like this:</div><div><br></div><div=
><font face=3D"Courier">auto &amp;&amp; should_decltypeauto() {</font></div=
><div><font face=3D"Courier">&nbsp; &nbsp; return 5; // Still broken. Retur=
n by value instead.</font></div><div><font face=3D"Courier">}</font></div><=
div><br></div><div>The recently bumped &ldquo;<font face=3D"Courier">as_con=
st</font>&rdquo; thread has a great example, but it needs a brief write-up:=
</div><div><pre><code> std::vector&lt;int&gt; vec;
 for (int val : vec | boost::adaptors::reversed
                    | boost::adaptors::uniqued) {
   // Do stuff with val
 }</code></pre></div><div><br></div><div>For that matter, this example come=
s from&nbsp;<a href=3D"http://cplusplus.github.io/EWG/ewg-active.html#120">=
EWG 120</a>&nbsp;and I should really cite any official issue tickets that m=
ay be touched, including LWG, EWG, and CWG. Help with that will be much app=
reciated too.</div><div><br></div><div>Of course, any example or reference =
submitters will be credited in the paper. Other than that, I turn 30 on the=
 fourth, so consider this my birthday present :) .</div><div><br></div><div=
>Abstract:</div><div>&ndash;&ndash;&ndash;</div><div>This proposal introduc=
es a model to describe the connection between a value and the object or obj=
ects needed to represent it. This&nbsp;enables a generalization of lifetime=
 extension, applicable to glvalue accessor function calls through some new =
function parameter&nbsp;syntax. The current lifetime extension behavior is =
also more elegantly described, and the &ldquo;temporary expression&rdquo; c=
ontroversy is&nbsp;resolved. The model may also enable strong copy elision =
guarantees.<br>&ndash;&ndash;&ndash;</div><div><br></div>Link: <a href=3D"h=
ttp://bit.ly/1vzN57X">http://bit.ly/1vzN57X</a><div><br></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=_56751B44-03EF-4257-B83E-24BBA6E07539--

.


Author: Richard Smith <richard@metafoo.co.uk>
Date: Thu, 2 Oct 2014 10:32:01 -0700
Raw View
--001a1133ba7886b3b3050473fed7
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Thu, Oct 2, 2014 at 2:44 AM, David Krauss <potswa@gmail.com> wrote:

> My next proposal is my most ambitious for Urbana. I think I=E2=80=99ve go=
t most of
> the specification down, but I really need a variety of examples of its us=
e,
> and a sense of real-world cases to be sure the spec is right.
>

I was writing a *very* similar paper for Urbana; would you be interested in
co-authorship? The only significant differences between your approach and
mine were
1) I used the "return" keyword rather than * to indicate an argument that
is captured by the return value (or by *this for a constructor).
2) I allow non-reference parameters to be marked 'return'.

I think your choice in (1) makes (2) impossible, but it's essential in
order for this mechanism to be composable. Consider:

struct A { int &&r; };
struct X { A a; }
X f(A a) { return { a }; }

X &&r =3D f({0});

With your proposal, it seems that you cannot mark that the X return value
of f should lifetime-extend the 'int' within the argument to 'f'; you'd
need to change 'f' to take its argument by reference. In my proposal, you'd
write:

  X f(A a return) { return { a }; }


FWIW, I disagree with this:

"The current lifetime extension rules describe neither the intent nor the
implementation practice.
This is the gist of CWG DR XXXX.

Standardizing current practice is not an option, due to lack of consensus.
Clang will persist the
result of a static_cast expression, but other implementations will not."

The lifetime extension rules are currently imprecise, in that they do not
make it clear that they only rely on the syntactic form of an expression.
But once you understand that, they are a good match for intent and
implementation practice (prior to CWG1299).

Clang persists the result of a static_cast expression because it's already
following (most of) the resolution of CWG1299. You are using the partial
implementation of a known direction as evidence that there is no direction.
We have consensus on the direction; the issue is in 'ready' status and is
starting to be adopted.

I think you should abandon your attempt to completely rewrite the rules
here, and try to fit your proposal into the framework of CWG1299 instead.
The effect of the language rules should be the same, but you'll have less
friction fitting your proposal into the standard.

Also:

"Conditional expressions cannot confer lifetime extension because one of
the alternative operands
will not exist."

CWG1299's wording allows lifetime extension through conditional
expressions. Take a look at n3918 and particularly the wording in
[expr.cond]p2, p4, and p6.

It=E2=80=99s designed to solve dangling references to temporaries by allowi=
ng
> potentially any temporary to get lifetime extension to the remainder of i=
ts
> scope. So, if you have an interesting dangling reference case, and you ca=
n
> format the code suitably for the printed page, please reply.
>
> Basic example:
>
> template< typename object >
> object const &
> id( object const & * o ) // * indicates that the result refers into the
> parameter.
>     { return o; }
>
> auto && x =3D id( foo{} ); // Not a dangling reference.
>
> Example with an accessor:
>
> class haz_int {
>     int haz;
> public:
>     int const & can_haz() * // * indicates that result refers into this
>         { return haz; }
> };
>
> auto && y =3D haz_int{}.can_haz(); // Not dangling.
>
> The magic does not extend to attempting to return a prvalue expression by
> reference; I don=E2=80=99t need examples like this:
>
> auto && should_decltypeauto() {
>     return 5; // Still broken. Return by value instead.
> }
>
> The recently bumped =E2=80=9Cas_const=E2=80=9D thread has a great example=
, but it needs a
> brief write-up:
>
>  std::vector<int> vec;
>  for (int val : vec | boost::adaptors::reversed
>                     | boost::adaptors::uniqued) {
>    // Do stuff with val
>  }
>
>
> For that matter, this example comes from EWG 120
> <http://cplusplus.github.io/EWG/ewg-active.html#120> and I should really
> cite any official issue tickets that may be touched, including LWG, EWG,
> and CWG. Help with that will be much appreciated too.
>
> Of course, any example or reference submitters will be credited in the
> paper. Other than that, I turn 30 on the fourth, so consider this my
> birthday present :) .
>
> Abstract:
> =E2=80=93=E2=80=93=E2=80=93
> This proposal introduces a model to describe the connection between a
> value and the object or objects needed to represent it. This enables a
> generalization of lifetime extension, applicable to glvalue accessor
> function calls through some new function parameter syntax. The current
> lifetime extension behavior is also more elegantly described, and the
> =E2=80=9Ctemporary expression=E2=80=9D controversy is resolved. The model=
 may also enable
> strong copy elision guarantees.
> =E2=80=93=E2=80=93=E2=80=93
>
> Link: http://bit.ly/1vzN57X
>
>  --
>
> ---
> 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/.
>

--=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/.

--001a1133ba7886b3b3050473fed7
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On T=
hu, Oct 2, 2014 at 2:44 AM, David Krauss <span dir=3D"ltr">&lt;<a href=3D"m=
ailto:potswa@gmail.com" target=3D"_blank">potswa@gmail.com</a>&gt;</span> w=
rote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8e=
x;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-styl=
e:solid;padding-left:1ex"><div style=3D"word-wrap:break-word"><div>My next =
proposal is my most ambitious for Urbana. I think I=E2=80=99ve got most of =
the specification down, but I really need a variety of examples of its use,=
 and a sense of real-world cases to be sure the spec is right.</div></div><=
/blockquote><div><br></div><div>I was writing a *very* similar paper for Ur=
bana; would you be interested in co-authorship? The only significant differ=
ences between your approach and mine were</div><div>1) I used the &quot;ret=
urn&quot; keyword rather than * to indicate an argument that is captured by=
 the return value (or by *this for a constructor).</div><div>2) I allow non=
-reference parameters to be marked &#39;return&#39;.</div><div><br></div><d=
iv>I think your choice in (1) makes (2) impossible, but it&#39;s essential =
in order for this mechanism to be composable. Consider:</div><div><br></div=
><div>struct A { int &amp;&amp;r; };</div><div>struct X { A a; }</div><div>=
X f(A a) { return { a }; }</div><div><br></div><div>X &amp;&amp;r =3D f({0}=
);</div><div><br></div><div>With your proposal, it seems that you cannot ma=
rk that the X return value of f should lifetime-extend the &#39;int&#39; wi=
thin the argument to &#39;f&#39;; you&#39;d need to change &#39;f&#39; to t=
ake its argument by reference. In my proposal, you&#39;d write:</div><div><=
br></div><div>=C2=A0 X f(A a return) { return { a }; }</div><div><br></div>=
<div><br></div><div>FWIW, I disagree with this:</div><div><br></div><div><d=
iv>&quot;The current lifetime extension rules describe neither the intent n=
or the implementation practice.=C2=A0</div><div>This is the gist of CWG DR =
XXXX.</div><div><br></div><div>Standardizing current practice is not an opt=
ion, due to lack of consensus. Clang will persist the=C2=A0</div><div>resul=
t of a static_cast expression, but other implementations will not.&quot;</d=
iv></div><div><br></div><div>The lifetime extension rules are currently imp=
recise, in that they do not make it clear that they only rely on the syntac=
tic form of an expression. But once you understand that, they are a good ma=
tch for intent and implementation practice (prior to CWG1299).</div><div><b=
r></div><div>Clang persists the result of a static_cast expression because =
it&#39;s already following (most of) the resolution of CWG1299. You are usi=
ng the partial implementation of a known direction as evidence that there i=
s no direction. We have consensus on the direction; the issue is in &#39;re=
ady&#39; status and is starting to be adopted.</div><div><br></div><div>I t=
hink you should abandon your attempt to completely rewrite the rules here, =
and try to fit your proposal into the framework of CWG1299 instead. The eff=
ect of the language rules should be the same, but you&#39;ll have less fric=
tion fitting your proposal into the standard.</div><div><br></div><div>Also=
:</div><div><br></div><div>&quot;Conditional expressions cannot confer life=
time extension because one of the alternative operands=C2=A0</div><div>will=
 not exist.&quot;</div><div><br></div><div>CWG1299&#39;s wording allows lif=
etime extension through conditional expressions. Take a look at=C2=A0n3918 =
and particularly the wording in [expr.cond]p2, p4, and p6.</div><div><br></=
div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;bor=
der-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:sol=
id;padding-left:1ex"><div style=3D"word-wrap:break-word"><div>It=E2=80=99s =
designed to solve dangling references to temporaries by allowing potentiall=
y any temporary to get lifetime extension to the remainder of its scope. So=
, if you have an interesting dangling reference case, and you can format th=
e code suitably for the printed page, please reply.</div><div><br></div><di=
v>Basic example:</div><div><br></div><div><font face=3D"Courier">template&l=
t; typename object &gt;</font></div><div><font face=3D"Courier">object cons=
t &amp;</font></div><div><font face=3D"Courier">id( object const &amp; * o =
) // * indicates that the result refers into the parameter.</font></div><di=
v><font face=3D"Courier">=C2=A0 =C2=A0 { return o; }</font></div><div><font=
 face=3D"Courier"><br></font></div><div><span style=3D"font-family:Courier"=
>auto &amp;&amp; x =3D id( foo{} ); // Not a dangling reference.</span></di=
v><div><br></div><div>Example with an accessor:</div><div><br></div><div><f=
ont face=3D"Courier">class haz_int {</font></div><div><font face=3D"Courier=
">=C2=A0 =C2=A0 int haz;</font></div><div><font face=3D"Courier">public:</f=
ont></div><div><font face=3D"Courier">=C2=A0 =C2=A0 int const &amp;=C2=A0ca=
n_haz() * // * indicates that result refers into this</font></div><div><fon=
t face=3D"Courier">=C2=A0 =C2=A0 =C2=A0 =C2=A0 { return haz; }</font></div>=
<div><font face=3D"Courier">};</font></div><div><font face=3D"Courier"><br>=
</font></div><div><font face=3D"Courier">auto &amp;&amp; y =3D haz_int{}.ca=
n_haz(); // Not dangling.</font></div><div><br></div><div>The magic does no=
t extend to attempting to return a prvalue expression by reference; I don=
=E2=80=99t need examples like this:</div><div><br></div><div><font face=3D"=
Courier">auto &amp;&amp; should_decltypeauto() {</font></div><div><font fac=
e=3D"Courier">=C2=A0 =C2=A0 return 5; // Still broken. Return by value inst=
ead.</font></div><div><font face=3D"Courier">}</font></div><div><br></div><=
div>The recently bumped =E2=80=9C<font face=3D"Courier">as_const</font>=E2=
=80=9D thread has a great example, but it needs a brief write-up:</div><div=
><pre><code> std::vector&lt;int&gt; vec;
 for (int val : vec | boost::adaptors::reversed
                    | boost::adaptors::uniqued) {
   // Do stuff with val
 }</code></pre></div><div><br></div><div>For that matter, this example come=
s from=C2=A0<a href=3D"http://cplusplus.github.io/EWG/ewg-active.html#120" =
target=3D"_blank">EWG 120</a>=C2=A0and I should really cite any official is=
sue tickets that may be touched, including LWG, EWG, and CWG. Help with tha=
t will be much appreciated too.</div><div><br></div><div>Of course, any exa=
mple or reference submitters will be credited in the paper. Other than that=
, I turn 30 on the fourth, so consider this my birthday present :) .</div><=
div><br></div><div>Abstract:</div><div>=E2=80=93=E2=80=93=E2=80=93</div><di=
v>This proposal introduces a model to describe the connection between a val=
ue and the object or objects needed to represent it. This=C2=A0enables a ge=
neralization of lifetime extension, applicable to glvalue accessor function=
 calls through some new function parameter=C2=A0syntax. The current lifetim=
e extension behavior is also more elegantly described, and the =E2=80=9Ctem=
porary expression=E2=80=9D controversy is=C2=A0resolved. The model may also=
 enable strong copy elision guarantees.<br>=E2=80=93=E2=80=93=E2=80=93</div=
><div><br></div>Link: <a href=3D"http://bit.ly/1vzN57X" target=3D"_blank">h=
ttp://bit.ly/1vzN57X</a><span class=3D""><font color=3D"#888888"><div><br><=
/div></font></span></div><span class=3D""><font color=3D"#888888">

<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" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</font></span></blockquote></div><br></div></div>

<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 />

--001a1133ba7886b3b3050473fed7--

.


Author: Marc <marc.glisse@gmail.com>
Date: Fri, 3 Oct 2014 16:35:58 -0700 (PDT)
Raw View
------=_Part_2378_1108782368.1412379358782
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Le jeudi 2 octobre 2014 19:32:03 UTC+2, Richard Smith a =C3=A9crit :
>
> On Thu, Oct 2, 2014 at 2:44 AM, David Krauss <pot...@gmail.com=20
> <javascript:>> wrote:
>
>> My next proposal is my most ambitious for Urbana. I think I=E2=80=99ve g=
ot most=20
>> of the specification down, but I really need a variety of examples of it=
s=20
>> use, and a sense of real-world cases to be sure the spec is right.
>>
>
> I was writing a *very* similar paper for Urbana; would you be interested=
=20
> in co-authorship? The only significant differences between your approach=
=20
> and mine were
> 1) I used the "return" keyword rather than * to indicate an argument that=
=20
> is captured by the return value (or by *this for a constructor).
> 2) I allow non-reference parameters to be marked 'return'.
>

I was pretty excited to see that 2 persons are working on this, and it=20
seems to be going in the right direction so I would like to encourage both=
=20
of you, but it won't solve my problem. I have a lot of wrappers all over=20
the place, and C++ is quite good at forwarding arguments (not "perfect" but=
=20
good enough), but forwarding returns is much harder because of temporaries.=
=20
I'll try to show a highly simplified example, not really representative,=20
but I hope it is still relevant. In practice, I mostly have this issue=20
inside transform_iterator::operator*.

Say I have these functions:

pair<T,U> factory();
T const& first(pair<T,U> const&);

I can currently write:

auto p=3Dfactory();
T const& t=3Dfirst(p);

With the proposals, if I understand correctly, a slight modification of=20
"first" would allow me to write:

T const& t=3Dfirst(factory());

But I have no way of composing the functions. I cannot create a function g=
=20
equivalent to calling factory and first:

T const& t=3Dg();

For that, I would probably need some kind of multi-return. Mock syntax (not=
=20
working, just to get the idea):

T const& g() return pair<T,U> {
  auto p return =3D factory();
  return first(p);
}

(if factory itself already has extra returns, I would also need to somehow=
=20
tell g to forward those)

Trying to avoid the multi-return, the closest I can think of would be (I am=
=20
making factory take an argument now to show that it still requires other=20
extensions):

T const& g(int i, pair<T,U> p return =3D factory(i)){return first(p);}

(bonus complication: I am not writing g by hand, I call=20
compose(first,factory) and it has to return a function object that behaves=
=20
like this g)

Currently I have g return T by value, using some heuristics and traits in=
=20
the function composer to guess if the return type should be decayed. I end=
=20
up doing many useless copies, which is not so nice (and no, moving is not=
=20
cheaper than copying for most types I handle). And then there are the cases=
=20
where copying is forbidden anyway...

--=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/.

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

<div dir=3D"ltr">Le jeudi 2 octobre 2014 19:32:03 UTC+2, Richard Smith a =
=C3=A9crit&nbsp;:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"l=
tr"><div><div class=3D"gmail_quote">On Thu, Oct 2, 2014 at 2:44 AM, David K=
rauss <span dir=3D"ltr">&lt;<a href=3D"javascript:" target=3D"_blank" gdf-o=
bfuscated-mailto=3D"3Mv1leYlNvgJ" onmousedown=3D"this.href=3D'javascript:';=
return true;" onclick=3D"this.href=3D'javascript:';return true;">pot...@gma=
il.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"=
margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,20=
4,204);border-left-style:solid;padding-left:1ex"><div style=3D"word-wrap:br=
eak-word"><div>My next proposal is my most ambitious for Urbana. I think I=
=E2=80=99ve got most of the specification down, but I really need a variety=
 of examples of its use, and a sense of real-world cases to be sure the spe=
c is right.</div></div></blockquote><div><br></div><div>I was writing a *ve=
ry* similar paper for Urbana; would you be interested in co-authorship? The=
 only significant differences between your approach and mine were</div><div=
>1) I used the "return" keyword rather than * to indicate an argument that =
is captured by the return value (or by *this for a constructor).</div><div>=
2) I allow non-reference parameters to be marked 'return'.</div></div></div=
></div></blockquote><div><br>I was pretty excited to see that 2 persons are=
 working on this, and it seems to be going in the right direction so I woul=
d like to encourage both of you, but it won't solve my problem. I have a lo=
t of wrappers all over the place, and C++ is quite good at forwarding argum=
ents (not "perfect" but good enough), but forwarding returns is much harder=
 because of temporaries. I'll try to show a highly simplified example, not =
really representative, but I hope it is still relevant. In practice, I most=
ly have this issue inside transform_iterator::operator*.<br><br>Say I have =
these functions:<br><br>pair&lt;T,U&gt; factory();<br>T const&amp; first(pa=
ir&lt;T,U&gt; const&amp;);<br><br>I can currently write:<br><br>auto p=3Dfa=
ctory();<br>T const&amp; t=3Dfirst(p);<br><br>With the proposals, if I unde=
rstand correctly, a slight modification of "first" would allow me to write:=
<br><br>T const&amp; t=3Dfirst(factory());<br><br>But I have no way of comp=
osing the functions. I cannot create a function g equivalent to calling fac=
tory and first:<br><br>T const&amp; t=3Dg();<br><br>For that, I would proba=
bly need some kind of multi-return. Mock syntax (not working, just to get t=
he idea):<br><br>T const&amp; g() return pair&lt;T,U&gt; {<br>&nbsp; auto p=
 return =3D factory();<br>&nbsp; return first(p);<br>}<br><br>(if factory i=
tself already has extra returns, I would also need to somehow tell g to for=
ward those)<br><br>Trying to avoid the multi-return, the closest I can thin=
k of would be (I am making factory take an argument now to show that it sti=
ll requires other extensions):<br><br>T const&amp; g(int i, pair&lt;T,U&gt;=
 p return =3D factory(i)){return first(p);}<br><br>(bonus complication: I a=
m not writing g by hand, I call compose(first,factory) and it has to return=
 a function object that behaves like this g)<br><br>Currently I have g retu=
rn T by value, using some heuristics and traits in the function composer to=
 guess if the return type should be decayed. I end up doing many useless co=
pies, which is not so nice (and no, moving is not cheaper than copying for =
most types I handle). And then there are the cases where copying is forbidd=
en anyway...<br></div></div>

<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 />

------=_Part_2378_1108782368.1412379358782--

.


Author: David Krauss <potswa@gmail.com>
Date: Sat, 4 Oct 2014 07:50:10 +0800
Raw View
--Apple-Mail=_CE836C37-5EAF-4336-891A-1CBBC927B960
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1


On 2014-10-04, at 7:35 AM, Marc <marc.glisse@gmail.com> wrote:

> But I have no way of composing the functions. I cannot create a function =
g equivalent to calling factory and first:
>=20
> T const& t=3Dg();
>=20
> For that, I would probably need some kind of multi-return.

This is covered by my qualified classes proposal. It allows for objects whi=
ch "rapidly decay" into other values, by conversion function. Lifetime exte=
nsion allows this conversion function to return a reference into the decaye=
d, but lifetime-extended object.

template< class pair >
struct first_of_pair : pair
    && & { // This class cannot be used as an rvalue nor an lvalue: it deca=
ys immediately.
    using pair::pair;

    operator typename pair::first_type & () return
        { return this->first; }
};

Any factory function returning this class will appear to be returning only =
the first object.

--=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=_CE836C37-5EAF-4336-891A-1CBBC927B960
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=ISO-8859-1

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-=
mode: space; -webkit-line-break: after-white-space;"><br><div><div>On 2014&=
ndash;10&ndash;04, at 7:35 AM, Marc &lt;<a href=3D"mailto:marc.glisse@gmail=
..com">marc.glisse@gmail.com</a>&gt; wrote:</div><br class=3D"Apple-intercha=
nge-newline"><blockquote type=3D"cite"><span style=3D"font-family: Helvetic=
a; font-size: 12px; font-style: normal; font-variant: normal; font-weight: =
normal; letter-spacing: normal; line-height: normal; orphans: auto; text-al=
ign: start; text-indent: 0px; text-transform: none; white-space: normal; wi=
dows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none;=
 display: inline !important;">But I have no way of composing the functions.=
 I cannot create a function g equivalent to calling factory and first:</spa=
n><br style=3D"font-family: Helvetica; font-size: 12px; font-style: normal;=
 font-variant: normal; font-weight: normal; letter-spacing: normal; line-he=
ight: normal; orphans: auto; text-align: start; text-indent: 0px; text-tran=
sform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-=
text-stroke-width: 0px;"><br style=3D"font-family: Helvetica; font-size: 12=
px; font-style: normal; font-variant: normal; font-weight: normal; letter-s=
pacing: normal; line-height: normal; orphans: auto; text-align: start; text=
-indent: 0px; text-transform: none; white-space: normal; widows: auto; word=
-spacing: 0px; -webkit-text-stroke-width: 0px;"><span 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: start; text-indent: 0px; text-transform: none; white-space: n=
ormal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; flo=
at: none; display: inline !important;">T const&amp; t=3Dg();</span><br styl=
e=3D"font-family: Helvetica; font-size: 12px; font-style: normal; font-vari=
ant: normal; font-weight: normal; letter-spacing: normal; line-height: norm=
al; orphans: auto; text-align: start; text-indent: 0px; text-transform: non=
e; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-strok=
e-width: 0px;"><br style=3D"font-family: Helvetica; font-size: 12px; font-s=
tyle: normal; font-variant: normal; font-weight: normal; letter-spacing: no=
rmal; line-height: normal; orphans: auto; text-align: start; text-indent: 0=
px; text-transform: none; white-space: normal; widows: auto; word-spacing: =
0px; -webkit-text-stroke-width: 0px;"><span style=3D"font-family: Helvetica=
; font-size: 12px; font-style: normal; font-variant: normal; font-weight: n=
ormal; letter-spacing: normal; line-height: normal; orphans: auto; text-ali=
gn: start; text-indent: 0px; text-transform: none; white-space: normal; wid=
ows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; =
display: inline !important;">For that, I would probably need some kind of m=
ulti-return.</span></blockquote><br></div><div>This is covered by my qualif=
ied classes proposal. It allows for objects which &ldquo;rapidly decay&rdqu=
o; into other values, by conversion function. Lifetime extension allows thi=
s conversion function to return a reference into the decayed, but lifetime-=
extended object.</div><div><br></div><div><font face=3D"Courier">template&l=
t; class pair &gt;</font></div><div><font face=3D"Courier">struct first_of_=
pair : pair</font></div><div><font face=3D"Courier">&nbsp; &nbsp; &amp;&amp=
; &amp; { // This class cannot be used as an rvalue nor an lvalue: it decay=
s immediately.</font></div><div><font face=3D"Courier">&nbsp; &nbsp; using =
pair::pair;</font></div><font face=3D"Courier"><br></font><div><font face=
=3D"Courier">&nbsp; &nbsp; operator typename pair::first_type &amp; () retu=
rn</font></div><div><font face=3D"Courier">&nbsp; &nbsp; &nbsp; &nbsp; { re=
turn this-&gt;first; }</font></div><div><font face=3D"Courier">};</font></d=
iv><div><br></div><div>Any factory function returning this class will appea=
r to be returning only the first object.</div><div><br></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=_CE836C37-5EAF-4336-891A-1CBBC927B960--

.


Author: David Krauss <potswa@gmail.com>
Date: Sat, 4 Oct 2014 08:00:09 +0800
Raw View
--Apple-Mail=_3ADEC9E4-14C3-47D8-90E4-123259B1486D
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1


On 2014-10-04, at 7:50 AM, David Krauss <potswa@gmail.com> wrote:

>=20
> On 2014-10-04, at 7:35 AM, Marc <marc.glisse@gmail.com> wrote:
>=20
>> But I have no way of composing the functions. I cannot create a function=
 g equivalent to calling factory and first:
>>=20
>> T const& t=3Dg();
>>=20
>> For that, I would probably need some kind of multi-return.
>=20
> This is covered by my qualified classes proposal. It allows for objects w=
hich "rapidly decay" into other values, by conversion function. Lifetime ex=
tension allows this conversion function to return a reference into the deca=
yed, but lifetime-extended object.
>=20
> template< class pair >
> struct first_of_pair : pair
>     && & { // This class cannot be used as an rvalue nor an lvalue: it de=
cays immediately.
>     using pair::pair;
>=20
>     operator typename pair::first_type & () return
>         { return this->first; }
> };
>=20
> Any factory function returning this class will appear to be returning onl=
y the first object.

By the way, as a refinement, you can preserve value category with a couple =
overloads. And I think "return" looks confusing in that context; I'll try e=
xport on for size.

template< class pair >
struct first_of_pair : pair
    && & { // This class cannot be used as an rvalue nor an lvalue: it deca=
ys immediately.
    using pair::pair;

    // These functions "export" internal state, so retain the object if nec=
essary.
    operator typename pair::first_type & () & export
        { return this->first; }
    operator typename pair::first_type const & () const & export
        { return this->first; }
    operator typename pair::first_type && () && export
        { return this->first; }
};

--=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=_3ADEC9E4-14C3-47D8-90E4-123259B1486D
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=ISO-8859-1

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-=
mode: space; -webkit-line-break: after-white-space;"><br><div><div>On 2014&=
ndash;10&ndash;04, at 7:50 AM, David Krauss &lt;<a href=3D"mailto:potswa@gm=
ail.com">potswa@gmail.com</a>&gt; wrote:</div><br class=3D"Apple-interchang=
e-newline"><blockquote type=3D"cite"><meta http-equiv=3D"Content-Type" cont=
ent=3D"text/html charset=3Dwindows-1252"><div style=3D"word-wrap: break-wor=
d; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><d=
iv><div>On 2014&ndash;10&ndash;04, at 7:35 AM, Marc &lt;<a href=3D"mailto:m=
arc.glisse@gmail.com">marc.glisse@gmail.com</a>&gt; wrote:</div><br class=
=3D"Apple-interchange-newline"><blockquote type=3D"cite"><span style=3D"fon=
t-family: Helvetica; font-size: 12px; font-style: normal; font-variant: nor=
mal; font-weight: normal; letter-spacing: normal; line-height: normal; orph=
ans: auto; text-align: start; text-indent: 0px; text-transform: none; white=
-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width:=
 0px; float: none; display: inline !important;">But I have no way of compos=
ing the functions. I cannot create a function g equivalent to calling facto=
ry and first:</span><br style=3D"font-family: Helvetica; font-size: 12px; f=
ont-style: normal; font-variant: normal; font-weight: normal; letter-spacin=
g: normal; line-height: normal; orphans: auto; text-align: start; text-inde=
nt: 0px; text-transform: none; white-space: normal; widows: auto; word-spac=
ing: 0px; -webkit-text-stroke-width: 0px;"><br style=3D"font-family: Helvet=
ica; font-size: 12px; font-style: normal; font-variant: normal; font-weight=
: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-=
align: start; text-indent: 0px; text-transform: none; white-space: normal; =
widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span sty=
le=3D"font-family: Helvetica; font-size: 12px; font-style: normal; font-var=
iant: normal; font-weight: normal; letter-spacing: normal; line-height: nor=
mal; orphans: auto; text-align: start; text-indent: 0px; text-transform: no=
ne; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stro=
ke-width: 0px; float: none; display: inline !important;">T const&amp; t=3Dg=
();</span><br 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: start; text-indent: 0px; t=
ext-transform: none; white-space: normal; widows: auto; word-spacing: 0px; =
-webkit-text-stroke-width: 0px;"><br 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;"><span style=3D"font=
-family: Helvetica; font-size: 12px; font-style: normal; font-variant: norm=
al; font-weight: normal; letter-spacing: normal; line-height: normal; orpha=
ns: auto; text-align: start; text-indent: 0px; text-transform: none; white-=
space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: =
0px; float: none; display: inline !important;">For that, I would probably n=
eed some kind of multi-return.</span></blockquote><br></div><div>This is co=
vered by my qualified classes proposal. It allows for objects which &ldquo;=
rapidly decay&rdquo; into other values, by conversion function. Lifetime ex=
tension allows this conversion function to return a reference into the deca=
yed, but lifetime-extended object.</div><div><br></div><div><font face=3D"C=
ourier">template&lt; class pair &gt;</font></div><div><font face=3D"Courier=
">struct first_of_pair : pair</font></div><div><font face=3D"Courier">&nbsp=
; &nbsp; &amp;&amp; &amp; { // This class cannot be used as an rvalue nor a=
n lvalue: it decays immediately.</font></div><div><font face=3D"Courier">&n=
bsp; &nbsp; using pair::pair;</font></div><font face=3D"Courier"><br></font=
><div><font face=3D"Courier">&nbsp; &nbsp; operator typename pair::first_ty=
pe &amp; () return</font></div><div><font face=3D"Courier">&nbsp; &nbsp; &n=
bsp; &nbsp; { return this-&gt;first; }</font></div><div><font face=3D"Couri=
er">};</font></div><div><br></div><div>Any factory function returning this =
class will appear to be returning only the first object.</div></div></block=
quote><br></div><div>By the way, as a refinement, you can preserve value ca=
tegory with a couple overloads. And I think &ldquo;return&rdquo; looks conf=
using in that context; I&rsquo;ll try <font face=3D"Courier">export</font> =
on for size.</div><div><br></div><div><font face=3D"Courier">template&lt; c=
lass pair &gt;<br>struct first_of_pair : pair<br>&nbsp; &nbsp; &amp;&amp; &=
amp; { // This class cannot be used as an rvalue nor an lvalue: it decays&n=
bsp;immediately.<br>&nbsp; &nbsp; using pair::pair;<br><br>&nbsp; &nbsp;&nb=
sp;// These functions &ldquo;export&rdquo; internal state, so retain the ob=
ject if necessary.<br>&nbsp; &nbsp; operator typename pair::first_type &amp=
; () &amp; export<br>&nbsp; &nbsp; &nbsp; &nbsp; { return this-&gt;first; }=
<br></font><span style=3D"font-family: Courier;">&nbsp; &nbsp; operator typ=
ename pair::first_type const &amp; () const &amp; export</span><br style=3D=
"font-family: Courier;"><span style=3D"font-family: Courier;">&nbsp; &nbsp;=
 &nbsp; &nbsp; { return this-&gt;first; }</span><br style=3D"font-family: C=
ourier;"><span style=3D"font-family: Courier;">&nbsp; &nbsp; operator typen=
ame pair::first_type &amp;&amp; () &amp;&amp; export</span><br style=3D"fon=
t-family: Courier;"><span style=3D"font-family: Courier;">&nbsp; &nbsp; &nb=
sp; &nbsp; { return this-&gt;first; }</span><br style=3D"font-family: Couri=
er;"><font face=3D"Courier">};<br></font><br></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=_3ADEC9E4-14C3-47D8-90E4-123259B1486D--

.


Author: Marc <marc.glisse@gmail.com>
Date: Sat, 4 Oct 2014 03:55:22 -0700 (PDT)
Raw View
------=_Part_8995_902433173.1412420123069
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Le samedi 4 octobre 2014 01:50:22 UTC+2, David Krauss a =C3=A9crit :
>
>
> On 2014=E2=80=9310=E2=80=9304, at 7:35 AM, Marc <marc....@gmail.com <java=
script:>> wrote:
>
> But I have no way of composing the functions. I cannot create a function =
g=20
> equivalent to calling factory and first:
>
> T const& t=3Dg();
>
> For that, I would probably need some kind of multi-return.
>
>
> This is covered by my qualified classes proposal. It allows for objects=
=20
> which =E2=80=9Crapidly decay=E2=80=9D into other values, by conversion fu=
nction. Lifetime=20
> extension allows this conversion function to return a reference into the=
=20
> decayed, but lifetime-extended object.
>
> template< class pair >
> struct first_of_pair : pair
>     && & { // This class cannot be used as an rvalue nor an lvalue: it=20
> decays immediately.
>     using pair::pair;
>
>     operator typename pair::first_type & () return
>         { return this->first; }
> };
>
> Any factory function returning this class will appear to be returning onl=
y=20
> the first object.
>

Thanks, indeed, returning a wrapper that delays evaluation to a conversion=
=20
operator seems to help a lot. To give an idea:

template<class Data, class Trans>
struct Hold {
  template<class F, class...Args>
  Hold(Trans t, F fac, Args&&...args): data(fac(forward<Args>(args)...)),=
=20
trans(t) {}
  Data data;
  Trans trans;
  operator decltype(auto)()const RETURN {return trans(data);}
}

template<class Factory, class Trans>
struct Compose {
  Factory fact; Trans trans;
  Compose(Factory x,Trans y):fact(x),trans(y){}
  operator auto()(Args&&...args)const{
    typedef decltype(fact(forward<Args>(args)...)) Data;
    return Hold<Data,Trans>(trans,fact,forward<Args>(args)...);
  }
}

template<class Factory, class Trans>
auto compose(Factory f, Trans t){ return Compose<Factory,Trans>(f, t); }

int main(){
  auto g =3D compose(compose(factory,first),identity);
  T const& t =3D g(3);
}


though the code is more complicated than I would hope, I would want some=20
way to detect that trans doesn't extend the lifetime of its argument so I=
=20
can skip the overhead in that case (I didn't really think of how that would=
=20
work), and obviously returning a wrapper instead of the right type is a=20
strong drawback. This last point is apparently where your other proposal=20
comes in, but it isn't clear to me that it completely solves the issue. If=
=20
I understand correctly, decltype(g(3)) would still be the Holder type, so I=
=20
would need to pass the result of decltype to some helper that takes a type=
=20
and returns the type itself except if it is a Holder, where it looks at its=
=20
converting type, when I want to know what the function is really supposed=
=20
to return. Well, hopefully I won't need to do that too often... I haven't=
=20
spent that long trying to imagine how to adapt my code, so maybe that's not=
=20
an issue at all, and maybe I am missing a bigger elephant.

--=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/.

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

<div dir=3D"ltr">Le samedi 4 octobre 2014 01:50:22 UTC+2, David Krauss a =
=C3=A9crit&nbsp;:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div style=3D=
"word-wrap:break-word"><br><div><div>On 2014=E2=80=9310=E2=80=9304, at 7:35=
 AM, Marc &lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mail=
to=3D"HtnSnsPl-FAJ" onmousedown=3D"this.href=3D'javascript:';return true;" =
onclick=3D"this.href=3D'javascript:';return true;">marc....@gmail.com</a>&g=
t; wrote:</div><br><blockquote type=3D"cite"><span style=3D"font-family:Hel=
vetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:nor=
mal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0=
px;text-transform:none;white-space:normal;word-spacing:0px;float:none;displ=
ay:inline!important">But I have no way of composing the functions. I cannot=
 create a function g equivalent to calling factory and first:</span><br sty=
le=3D"font-family:Helvetica;font-size:12px;font-style:normal;font-variant:n=
ormal;font-weight:normal;letter-spacing:normal;line-height:normal;text-alig=
n:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing=
:0px"><br style=3D"font-family:Helvetica;font-size:12px;font-style:normal;f=
ont-variant:normal;font-weight:normal;letter-spacing:normal;line-height:nor=
mal;text-align:start;text-indent:0px;text-transform:none;white-space:normal=
;word-spacing:0px"><span style=3D"font-family:Helvetica;font-size:12px;font=
-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;=
line-height:normal;text-align:start;text-indent:0px;text-transform:none;whi=
te-space:normal;word-spacing:0px;float:none;display:inline!important">T con=
st&amp; t=3Dg();</span><br style=3D"font-family:Helvetica;font-size:12px;fo=
nt-style:normal;font-variant:normal;font-weight:normal;letter-spacing:norma=
l;line-height:normal;text-align:start;text-indent:0px;text-transform:none;w=
hite-space:normal;word-spacing:0px"><br style=3D"font-family:Helvetica;font=
-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-=
spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-tra=
nsform:none;white-space:normal;word-spacing:0px"><span style=3D"font-family=
:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight=
:normal;letter-spacing:normal;line-height:normal;text-align:start;text-inde=
nt:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;d=
isplay:inline!important">For that, I would probably need some kind of multi=
-return.</span></blockquote><br></div><div>This is covered by my qualified =
classes proposal. It allows for objects which =E2=80=9Crapidly decay=E2=80=
=9D into other values, by conversion function. Lifetime extension allows th=
is conversion function to return a reference into the decayed, but lifetime=
-extended object.</div><div><br></div><div><font face=3D"Courier">template&=
lt; class pair &gt;</font></div><div><font face=3D"Courier">struct first_of=
_pair : pair</font></div><div><font face=3D"Courier">&nbsp; &nbsp; &amp;&am=
p; &amp; { // This class cannot be used as an rvalue nor an lvalue: it deca=
ys immediately.</font></div><div><font face=3D"Courier">&nbsp; &nbsp; using=
 pair::pair;</font></div><font face=3D"Courier"><br></font><div><font face=
=3D"Courier">&nbsp; &nbsp; operator typename pair::first_type &amp; () retu=
rn</font></div><div><font face=3D"Courier">&nbsp; &nbsp; &nbsp; &nbsp; { re=
turn this-&gt;first; }</font></div><div><font face=3D"Courier">};</font></d=
iv><div><br></div><div>Any factory function returning this class will appea=
r to be returning only the first object.</div></div></blockquote><div><br>T=
hanks, indeed, returning a wrapper that delays evaluation to a conversion o=
perator seems to help a lot. To give an idea:<br><br>template&lt;class Data=
, class Trans&gt;<br>struct Hold {<br>&nbsp; template&lt;class F, class...A=
rgs&gt;<br>&nbsp; Hold(Trans t, F fac, Args&amp;&amp;...args): data(fac(for=
ward&lt;Args&gt;(args)...)), trans(t) {}<br>&nbsp; Data data;<br>&nbsp; Tra=
ns trans;<br>&nbsp; operator decltype(auto)()const RETURN {return trans(dat=
a);}<br>}<br><br>template&lt;class Factory, class Trans&gt;<br>struct Compo=
se {<br>&nbsp; Factory fact; Trans trans;<br>&nbsp; Compose(Factory x,Trans=
 y):fact(x),trans(y){}<br>&nbsp; operator auto()(Args&amp;&amp;...args)cons=
t{<br>&nbsp;&nbsp;&nbsp; typedef decltype(fact(forward&lt;Args&gt;(args)...=
)) Data;<br>&nbsp;&nbsp;&nbsp; return Hold&lt;Data,Trans&gt;(trans,fact,for=
ward&lt;Args&gt;(args)...);<br>&nbsp; }<br>}<br><br>template&lt;class Facto=
ry, class Trans&gt;<br>auto compose(Factory f, Trans t){ return Compose&lt;=
Factory,Trans&gt;(f, t); }<br><br>int main(){<br>&nbsp; auto g =3D compose(=
compose(factory,first),identity);<br>&nbsp; T const&amp; t =3D g(3);<br>}<b=
r><br><br>though the code is more complicated than I would hope, I would wa=
nt some way to detect that trans doesn't extend the lifetime of its argumen=
t so I can skip the overhead in that case (I didn't really think of how tha=
t would work), and obviously returning a wrapper instead of the right type =
is a strong drawback. This last point is apparently where your other propos=
al comes in, but it isn't clear to me that it completely solves the issue. =
If I understand correctly, decltype(g(3)) would still be the Holder type, s=
o I would need to pass the result of decltype to some helper that takes a t=
ype and returns the type itself except if it is a Holder, where it looks at=
 its converting type, when I want to know what the function is really suppo=
sed to return. Well, hopefully I won't need to do that too often... I haven=
't spent that long trying to imagine how to adapt my code, so maybe that's =
not an issue at all, and maybe I am missing a bigger elephant.<br></div></d=
iv>

<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 />

------=_Part_8995_902433173.1412420123069--

.


Author: Marc <marc.glisse@gmail.com>
Date: Sat, 4 Oct 2014 06:03:59 -0700 (PDT)
Raw View
------=_Part_8801_237777897.1412427840006
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Le samedi 4 octobre 2014 14:23:06 UTC+2, David Krauss a =C3=A9crit :
>
>
> On 2014=E2=80=9310=E2=80=9304, at 6:55 PM, Marc <marc....@gmail.com <java=
script:>> wrote:
>
> If I understand correctly, decltype(g(3)) would still be the Holder type,=
=20
> so I would need to pass the result of decltype to some helper that takes =
a=20
> type and returns the type itself except if it is a Holder
>
>
> Yes, that=E2=80=99s an important question in the other proposal. std::dec=
ay=20
> should cover your case;
>

Well, no, I don't want to decay, I want "const T&" in my pair example and=
=20
at best decay would give me T.
=20

> already it=E2=80=99s often needed inside decltype. In cases where the dec=
ayed-to=20
> type cannot be passed by value, so decay doesn=E2=80=99t work, I proposed=
 a new=20
> metafunction std::as_temporary.
>
> Link: https://isocpp.org/files/papers/n4149.pdf
>

Ah, thanks! I was reading an older version where as_temporary wasn't as=20
clear. I am wondering if result_of should maybe automatically use that=20
metafunction (we can still use decltype to get the non-converted type).=20
Basically, I am afraid as_temporary is something that will need to be used=
=20
in generic code but that we will only ever remember to use when writing=20
weird types. Maybe that's not an issue, I can't tell without using it for a=
=20
while.

You wouldn't happen to have a prototype implementation for either of the=20
proposals, would you?

--=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/.

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

<div dir=3D"ltr">Le samedi 4 octobre 2014 14:23:06 UTC+2, David Krauss a =
=C3=A9crit&nbsp;:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div style=3D=
"word-wrap:break-word"><br><div><div>On 2014=E2=80=9310=E2=80=9304, at 6:55=
 PM, Marc &lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mail=
to=3D"Hy_RMSmaPKEJ" onmousedown=3D"this.href=3D'javascript:';return true;" =
onclick=3D"this.href=3D'javascript:';return true;">marc....@gmail.com</a>&g=
t; wrote:</div><br><blockquote type=3D"cite"><span style=3D"font-family:Hel=
vetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:nor=
mal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0=
px;text-transform:none;white-space:normal;word-spacing:0px;float:none;displ=
ay:inline!important">If I understand correctly, decltype(g(3)) would still =
be the Holder type, so I would need to pass the result of decltype to some =
helper that takes a type and returns the type itself except if it is a Hold=
er</span></blockquote></div><br><div>Yes, that=E2=80=99s an important quest=
ion in the other proposal. <font face=3D"Courier">std::decay</font> should =
cover your case;</div></div></blockquote><div><br>Well, no, I don't want to=
 decay, I want "const T&amp;" in my pair example and at best decay would gi=
ve me T.<br>&nbsp;</div><blockquote class=3D"gmail_quote" style=3D"margin: =
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div s=
tyle=3D"word-wrap:break-word"><div> already it=E2=80=99s often needed insid=
e <font face=3D"Courier">decltype</font>. In cases where the decayed-to typ=
e cannot be passed by value, so <font face=3D"Courier">decay</font> doesn=
=E2=80=99t work, I proposed a new metafunction <font face=3D"Courier">std::=
as_temporary</font>.</div><div><br></div><div>Link: <a href=3D"https://isoc=
pp.org/files/papers/n4149.pdf" target=3D"_blank" onmousedown=3D"this.href=
=3D'https://www.google.com/url?q\75https%3A%2F%2Fisocpp.org%2Ffiles%2Fpaper=
s%2Fn4149.pdf\46sa\75D\46sntz\0751\46usg\75AFQjCNEAQUc3gXFTtkJjAOnP8eCXC-fw=
2Q';return true;" onclick=3D"this.href=3D'https://www.google.com/url?q\75ht=
tps%3A%2F%2Fisocpp.org%2Ffiles%2Fpapers%2Fn4149.pdf\46sa\75D\46sntz\0751\46=
usg\75AFQjCNEAQUc3gXFTtkJjAOnP8eCXC-fw2Q';return true;">https://isocpp.org/=
files/<wbr>papers/n4149.pdf</a></div></div></blockquote><div><br>Ah, thanks=
! I was reading an older version where as_temporary wasn't as clear. I am w=
ondering if result_of should maybe automatically use that metafunction (we =
can still use decltype to get the non-converted type). Basically, I am afra=
id as_temporary is something that will need to be used in generic code but =
that we will only ever remember to use when writing weird types. Maybe that=
's not an issue, I can't tell without using it for a while.<br><br>You woul=
dn't happen to have a prototype implementation for either of the proposals,=
 would you?<br></div></div>

<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 />

------=_Part_8801_237777897.1412427840006--

.


Author: David Krauss <potswa@gmail.com>
Date: Sat, 4 Oct 2014 20:22:04 +0800
Raw View
--Apple-Mail=_38B8A9BB-A3A7-4798-9797-930256F2DAEE
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1


On 2014-10-04, at 6:55 PM, Marc <marc.glisse@gmail.com> wrote:

> If I understand correctly, decltype(g(3)) would still be the Holder type,=
 so I would need to pass the result of decltype to some helper that takes a=
 type and returns the type itself except if it is a Holder

Yes, that's an important question in the other proposal. std::decay should =
cover your case; already it's often needed inside decltype. In cases where =
the decayed-to type cannot be passed by value, so decay doesn't work, I pro=
posed a new metafunction std::as_temporary.

Link: https://isocpp.org/files/papers/n4149.pdf

--=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=_38B8A9BB-A3A7-4798-9797-930256F2DAEE
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=ISO-8859-1

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-=
mode: space; -webkit-line-break: after-white-space;"><br><div><div>On 2014&=
ndash;10&ndash;04, at 6:55 PM, Marc &lt;<a href=3D"mailto:marc.glisse@gmail=
..com">marc.glisse@gmail.com</a>&gt; wrote:</div><br class=3D"Apple-intercha=
nge-newline"><blockquote type=3D"cite"><span style=3D"font-family: Helvetic=
a; font-size: 12px; font-style: normal; font-variant: normal; font-weight: =
normal; letter-spacing: normal; line-height: normal; orphans: auto; text-al=
ign: start; text-indent: 0px; text-transform: none; white-space: normal; wi=
dows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none;=
 display: inline !important;">If I understand correctly, decltype(g(3)) wou=
ld still be the Holder type, so I would need to pass the result of decltype=
 to some helper that takes a type and returns the type itself except if it =
is a Holder</span></blockquote></div><br><div>Yes, that&rsquo;s an importan=
t question in the other proposal. <font face=3D"Courier">std::decay</font> =
should cover your case; already it&rsquo;s often needed inside <font face=
=3D"Courier">decltype</font>. In cases where the decayed-to type cannot be =
passed by value, so <font face=3D"Courier">decay</font> doesn&rsquo;t work,=
 I proposed a new metafunction <font face=3D"Courier">std::as_temporary</fo=
nt>.</div><div><br></div><div>Link: <a href=3D"https://isocpp.org/files/pap=
ers/n4149.pdf">https://isocpp.org/files/papers/n4149.pdf</a></div><div><br>=
</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=_38B8A9BB-A3A7-4798-9797-930256F2DAEE--

.


Author: David Krauss <potswa@gmail.com>
Date: Sat, 4 Oct 2014 20:44:35 +0800
Raw View
--Apple-Mail=_86E524E5-C543-49A0-AB1E-439EE88BE87B
Content-Type: text/plain; charset=ISO-8859-1


On 2014-10-04, at 6:55 PM, Marc <marc.glisse@gmail.com> wrote:

>   operator decltype(auto)()const RETURN {return trans(data);}

Unfortunately, the semantics of operator auto() have not been widely agreed, although the specification appears to require what you are expressing and it is specifically allowed in the syntax.

I'm not sure if this needs resolution requires as a DR, an analysis paper, or per-platform bug reports.

>   operator auto()(Args&&...args)const{


Hmm, conversion functions can't have parameters.

Would you mind a quick description in English of the context of your problem? It would be very helpful if I'm going to adapt your example to the paper.

If compose is only going to be used in a context that permits lifetime extension, i.e. never in a constructor mem-initializer or for an object on the heap, you can just take factory, first, and identity by reference and lifetime-extend then directly.

template<class Factory, class Trans>
struct Compose {
  Factory && fact;
  Trans && trans;

template<class Factory, class Trans>
auto compose(export Factory && f, export Trans && t){
    return Compose<Factory,Trans>(std::forward< Factory >( f ),
                                  std::forward< Factory >( t ) );
}

--

---
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/.

--Apple-Mail=_86E524E5-C543-49A0-AB1E-439EE88BE87B
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=ISO-8859-1

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-=
mode: space; -webkit-line-break: after-white-space;"><br><div><div>On 2014&=
ndash;10&ndash;04, at 6:55 PM, Marc &lt;<a href=3D"mailto:marc.glisse@gmail=
..com">marc.glisse@gmail.com</a>&gt; wrote:</div><br class=3D"Apple-intercha=
nge-newline"><blockquote type=3D"cite"><span style=3D"font-family: Helvetic=
a; font-size: 12px; font-style: normal; font-variant: normal; font-weight: =
normal; letter-spacing: normal; line-height: normal; orphans: auto; text-al=
ign: start; text-indent: 0px; text-transform: none; white-space: normal; wi=
dows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none;=
 display: inline !important;">&nbsp; operator decltype(auto)()const RETURN =
{return trans(data);}</span><br style=3D"font-family: Helvetica; font-size:=
 12px; font-style: normal; font-variant: normal; font-weight: normal; lette=
r-spacing: normal; line-height: normal; orphans: auto; text-align: start; t=
ext-indent: 0px; text-transform: none; white-space: normal; widows: auto; w=
ord-spacing: 0px; -webkit-text-stroke-width: 0px;"></blockquote></div><br><=
div>Unfortunately, the semantics of operator auto() have not been widely ag=
reed, although the specification appears to require what you are expressing=
 and it is specifically allowed in the syntax.</div><div><br></div><div>I&r=
squo;m not sure if this needs resolution requires as a DR, an analysis pape=
r, or per-platform bug reports.</div><div><br></div><div><blockquote type=
=3D"cite">&nbsp; operator auto()(Args&amp;&amp;...args)const{<br></blockquo=
te></div><div><br></div><div>Hmm, conversion functions can&rsquo;t have par=
ameters.</div><div><br></div><div>Would you mind a quick description in Eng=
lish of the context of your problem? It would be very helpful if I&rsquo;m =
going to adapt your example to the paper.</div><div><br></div><div>If <font=
 face=3D"Courier">compose</font> is only going to be used in a context that=
 permits lifetime extension, i.e. never in a constructor mem-initializer or=
 for an object on the heap, you can just take&nbsp;<font face=3D"Courier">f=
actory</font>,&nbsp;<font face=3D"Courier">first</font>, and&nbsp;<font fac=
e=3D"Courier">identity</font>&nbsp;by reference and lifetime-extend then di=
rectly.</div><div><br></div><div><font face=3D"Courier">template&lt;class F=
actory, class Trans&gt;<br>struct Compose {<br>&nbsp; Factory &amp;&amp; fa=
ct;</font></div><div><font face=3D"Courier">&nbsp; Trans &amp;&amp; trans;<=
br></font></div><div><font face=3D"Courier"><br></font></div><div><font fac=
e=3D"Courier">template&lt;class Factory, class Trans&gt;<br>auto compose(ex=
port Factory &amp;&amp; f, export Trans &amp;&amp; t){</font></div><div><fo=
nt face=3D"Courier">&nbsp; &nbsp; return Compose&lt;Factory,Trans&gt;(std::=
forward&lt; Factory &gt;( f ),</font></div><div><font face=3D"Courier">&nbs=
p; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &n=
bsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; std::forward&lt; Factory &gt;( t ) =
);</font></div><div><font face=3D"Courier">}</font><br></div><div><font fac=
e=3D"Courier"><br></font></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=_86E524E5-C543-49A0-AB1E-439EE88BE87B--

.


Author: David Krauss <potswa@gmail.com>
Date: Sat, 4 Oct 2014 23:00:50 +0800
Raw View
--Apple-Mail=_D51F5445-193D-4466-9988-6D07CD81BA1B
Content-Type: text/plain; charset=ISO-8859-1


On 2014-10-04, at 9:03 PM, Marc <marc.glisse@gmail.com> wrote:

> Maybe that's not an issue, I can't tell without using it for a while.

Me neither. Time will tell, if it gains traction.

Another alternative to as_temporary is decltype(()), with doubled parentheses. This causes identifiers to semi-decay to references, reflecting value category, regarding their behavior as subexpressions. It could perhaps be argued that there is a pattern:

decltype(x) => Pure introspection, or declare a semantically identical copy of a variable.
decay_t<decltype(x)> => Value semantics, declare a new copy of a variable's value.
decltype((x)) => Subexpression semantics, determine whether something is one-use, expiring, or persistent.

For now, mere survival is the top priority, I think the proposal is taking the low-risk route.

> You wouldn't happen to have a prototype implementation for either of the proposals, would you?

Nope. Right now I'm just generating ideas, focusing on correctness and safety, and hoping for endorsement.

--

---
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/.

--Apple-Mail=_D51F5445-193D-4466-9988-6D07CD81BA1B
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=ISO-8859-1

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-=
mode: space; -webkit-line-break: after-white-space;"><br><div><div>On 2014&=
ndash;10&ndash;04, at 9:03 PM, Marc &lt;<a href=3D"mailto:marc.glisse@gmail=
..com">marc.glisse@gmail.com</a>&gt; wrote:</div><br class=3D"Apple-intercha=
nge-newline"><blockquote type=3D"cite"><div dir=3D"ltr" style=3D"font-famil=
y: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; fo=
nt-weight: normal; letter-spacing: normal; line-height: normal; orphans: au=
to; text-align: start; text-indent: 0px; text-transform: none; white-space:=
 normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">=
Maybe that's not an issue, I can't tell without using it for a while.<br></=
div></blockquote><div><br></div><div>Me neither. Time will tell, if it gain=
s traction.</div><div><br></div><div>Another alternative to <font face=3D"C=
ourier">as_temporary</font> is <font face=3D"Courier">decltype(())</font>, =
with doubled parentheses. This causes identifiers to semi-decay to referenc=
es, reflecting value category, regarding their behavior as subexpressions. =
It could perhaps be argued that there is a pattern:</div><div><br></div><di=
v><font face=3D"Courier">decltype(x)</font> =3D&gt; Pure introspection, or =
declare a semantically identical copy of a variable.</div><div><font face=
=3D"Courier">decay_t&lt;decltype(x)&gt;</font> =3D&gt; Value semantics, dec=
lare a new copy of a variable&rsquo;s value.</div><div><font face=3D"Courie=
r">decltype((x))</font> =3D&gt; Subexpression semantics, determine whether =
something is one-use, expiring, or persistent.</div><div><br></div><div>For=
 now, mere survival is the top priority, I think the proposal is taking the=
 low-risk route.</div><br><blockquote type=3D"cite"><div dir=3D"ltr" style=
=3D"font-family: Helvetica; font-size: 12px; font-style: normal; font-varia=
nt: normal; font-weight: normal; letter-spacing: normal; line-height: norma=
l; orphans: auto; text-align: start; text-indent: 0px; text-transform: none=
; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke=
-width: 0px;">You wouldn't happen to have a prototype implementation for ei=
ther of the proposals, would you?</div></blockquote><br></div><div>Nope. Ri=
ght now I&rsquo;m just generating ideas, focusing on correctness and safety=
, and hoping for endorsement.&nbsp;</div><br></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=_D51F5445-193D-4466-9988-6D07CD81BA1B--

.


Author: Marc <marc.glisse@gmail.com>
Date: Sat, 4 Oct 2014 12:02:21 -0700 (PDT)
Raw View
------=_Part_4744_386724629.1412449341839
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Le samedi 4 octobre 2014 15:31:02 UTC+2, David Krauss a =C3=A9crit :
>
>
> On 2014=E2=80=9310=E2=80=9304, at 6:55 PM, Marc <marc....@gmail.com <java=
script:>> wrote:
>
>   operator decltype(auto)()const RETURN {return trans(data);}
>
>
> Unfortunately, the semantics of operator auto() have not been widely=20
> agreed, although the specification appears to require what you are=20
> expressing and it is specifically allowed in the syntax.
>

I did try to use what I believe are the C++14 semantics (i.e. *not* the=20
expression-template related proposal), which now seem unlikely to change.
=20

> I=E2=80=99m not sure if this needs resolution requires as a DR, an analys=
is paper,=20
> or per-platform bug reports.
>
>   operator auto()(Args&&...args)const{
>
>
> Hmm, conversion functions can=E2=80=99t have parameters.
>

Oups, I swapped the 2 words, it was supposed to be "auto operator()" (g is=
=20
callable in the example, and I am too lazy to spell out the return type).
=20

> Would you mind a quick description in English of the context of your=20
> problem? It would be very helpful if I=E2=80=99m going to adapt your exam=
ple to the=20
> paper.
>

I have a functor that takes iterators to points and computes something. Now=
=20
I write a wrapper to the point type and use transform_iterator to create a=
=20
functor that takes iterators to wrappers and delegates to the first functor=
=20
(unwrapping returns a reference to the wrapped object). I also have points=
=20
where the coordinates use a different type, and I use transform_iterator to=
=20
create a functor that takes iterators to those new points, and delegates to=
=20
the first functor (converting new points to old points (prvalue)). I may=20
also have iterators to segments and want to compute something about their=
=20
first extremity, again delegating to the first functor, and the access to=
=20
the first extremity returns a reference (the same functor is used in the=20
process of getting an iterator to the coordinates of the point, so copying=
=20
would break). And I want to be able to compose all those things, preferably=
=20
without copying too much. Normally, in the transform_iterator, operator*=20
returns transform(*nested_iterator), where *nested_iterator calls=20
transform2(*nested2_iterator), etc. If one transformation returns a prvalue=
=20
(say a point with converted coordinates), and the next one returns a=20
reference into its argument (for instance unwrapping), I get a dangling=20
reference (or I overload the unwrapping to copy when it takes an xvalue=20
argument, but I also needed a C++03 version...). All those new functors are=
=20
defined automatically for many different computations taking many different=
=20
objects or iterators, I can't specialize each of them.

Not sure that will help you much with the paper... Good luck anyway.

If compose is only going to be used in a context that permits lifetime=20
> extension, i.e. never in a constructor mem-initializer or for an object o=
n=20
> the heap, you can just take factory, first, and identity by reference and=
=20
> lifetime-extend then directly.
>

I didn't focus on that in my example, and it is clearly secondary in my=20
code, but yes, there should be some possible improvements there.

--=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/.

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

<div dir=3D"ltr">Le samedi 4 octobre 2014 15:31:02 UTC+2, David Krauss a =
=C3=A9crit&nbsp;:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div style=3D=
"word-wrap:break-word"><br><div><div>On 2014=E2=80=9310=E2=80=9304, at 6:55=
 PM, Marc &lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mail=
to=3D"ML-Roen2G8sJ" onmousedown=3D"this.href=3D'javascript:';return true;" =
onclick=3D"this.href=3D'javascript:';return true;">marc....@gmail.com</a>&g=
t; wrote:</div><br><blockquote type=3D"cite"><span style=3D"font-family:Hel=
vetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:nor=
mal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0=
px;text-transform:none;white-space:normal;word-spacing:0px;float:none;displ=
ay:inline!important">&nbsp; operator decltype(auto)()const RETURN {return t=
rans(data);}</span><br style=3D"font-family:Helvetica;font-size:12px;font-s=
tyle:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;li=
ne-height:normal;text-align:start;text-indent:0px;text-transform:none;white=
-space:normal;word-spacing:0px"></blockquote></div><br><div>Unfortunately, =
the semantics of operator auto() have not been widely agreed, although the =
specification appears to require what you are expressing and it is specific=
ally allowed in the syntax.</div></div></blockquote><div><br>I did try to u=
se what I believe are the C++14 semantics (i.e. *not* the expression-templa=
te related proposal), which now seem unlikely to change.<br>&nbsp;</div><bl=
ockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border=
-left: 1px #ccc solid;padding-left: 1ex;"><div style=3D"word-wrap:break-wor=
d"><div>I=E2=80=99m not sure if this needs resolution requires as a DR, an =
analysis paper, or per-platform bug reports.</div><div><br></div><div><bloc=
kquote type=3D"cite">&nbsp; operator auto()(Args&amp;&amp;...args)const{<br=
></blockquote></div><div><br></div><div>Hmm, conversion functions can=E2=80=
=99t have parameters.</div></div></blockquote><div><br>Oups, I swapped the =
2 words, it was supposed to be "auto operator()" (g is callable in the exam=
ple, and I am too lazy to spell out the return type).<br>&nbsp;</div><block=
quote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-le=
ft: 1px #ccc solid;padding-left: 1ex;"><div style=3D"word-wrap:break-word">=
<div>Would you mind a quick description in English of the context of your p=
roblem? It would be very helpful if I=E2=80=99m going to adapt your example=
 to the paper.</div></div></blockquote><div><br>I have a functor that takes=
 iterators to points and computes something. Now I write a wrapper to the p=
oint type and use transform_iterator to create a functor that takes iterato=
rs to wrappers and delegates to the first functor (unwrapping returns a ref=
erence to the wrapped object). I also have points where the coordinates use=
 a different type, and I use transform_iterator to create a functor that ta=
kes iterators to those new points, and delegates to the first functor (conv=
erting new points to old points (prvalue)). I may also have iterators to se=
gments and want to compute something about their first extremity, again del=
egating to the first functor, and the access to the first extremity returns=
 a reference (the same functor is used in the process of getting an iterato=
r to the coordinates of the point, so copying would break). And I want to b=
e able to compose all those things, preferably without copying too much. No=
rmally, in the transform_iterator, operator* returns transform(*nested_iter=
ator), where *nested_iterator calls transform2(*nested2_iterator), etc. If =
one transformation returns a prvalue (say a point with converted coordinate=
s), and the next one returns a reference into its argument (for instance un=
wrapping), I get a dangling reference (or I overload the unwrapping to copy=
 when it takes an xvalue argument, but I also needed a C++03 version...). A=
ll those new functors are defined automatically for many different computat=
ions taking many different objects or iterators, I can't specialize each of=
 them.<br><br>Not sure that will help you much with the paper... Good luck =
anyway.<br><br></div><blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div styl=
e=3D"word-wrap:break-word"><div>If <font face=3D"Courier">compose</font> is=
 only going to be used in a context that permits lifetime extension, i.e. n=
ever in a constructor mem-initializer or for an object on the heap, you can=
 just take&nbsp;<font face=3D"Courier">factory</font>,&nbsp;<font face=3D"C=
ourier">first</font>, and&nbsp;<font face=3D"Courier">identity</font>&nbsp;=
by reference and lifetime-extend then directly.</div></div></blockquote><di=
v><br>I didn't focus on that in my example, and it is clearly secondary in =
my code, but yes, there should be some possible improvements there.<br></di=
v></div>

<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 />

------=_Part_4744_386724629.1412449341839--

.


Author: Jeremy Maitin-Shepard <jeremy@jeremyms.com>
Date: Thu, 9 Oct 2014 11:33:58 -0700 (PDT)
Raw View
------=_Part_24_1304299547.1412879638281
Content-Type: text/plain; charset=UTF-8

I very much like the direction this and the proposal Richard Smith hinted
at are headed.

However, I believe the generalized lifetime extension would be much more
useful and powerful if it were compatible with metaprogramming.

I don't have a concrete proposal but my thinking is along these lines,
inspired by the Rust lifetime system (of which I have only limited
knowledge):
 - We introduce a new type of constexpr object allowed as a non-type
template parameter for functions and type definitions that corresponds to
lifetimes.  However, these parameters would explicitly *not* affect code
generation in any way.  These lifetime parameters would therefore behave
more like Java generics than C++ template parameters: lifetime objects
would be opaque tokens, with no way to specialize on or compare lifetimes.
They would also be usable only at compile-time.
- We would have a way of associating lifetimes with references (and perhaps
also const pointers?).  I think it would only be useful to do this for
function parameters, return values, and class/struct members.  I don't know
what the best syntax would be.
- Constexpr functions would be used for metaprogramming using lifetimes.  A
default constructed lifetime would refer to an empty lifetime.  We would
also need a builtin operation returning a new lifetime object corresponding
to the union of two lifetime objects.

It is not clear how these lifetime parameters should interact with class
identity, but it seems necessary to support composability.

Perhaps there could be some form of automatic lifetime deduction as well.

--

---
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/.

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

<div dir=3D"ltr">I very much like the direction this and the proposal Richa=
rd Smith hinted at are headed.<br><br>However, I believe the generalized li=
fetime extension would be much more useful and powerful if it were compatib=
le with metaprogramming.<br><br>I don't have a concrete proposal but my thi=
nking is along these lines, inspired by the Rust lifetime system (of which =
I have only limited knowledge):<br>&nbsp;- We introduce a new type of const=
expr object allowed as a non-type template parameter for functions and type=
 definitions that corresponds to lifetimes.&nbsp; However, these parameters=
 would explicitly *not* affect code generation in any way.&nbsp; These life=
time parameters would therefore behave more like Java generics than C++ tem=
plate parameters: lifetime objects would be opaque tokens, with no way to s=
pecialize on or compare lifetimes.&nbsp; They would also be usable only at =
compile-time.<br>- We would have a way of associating lifetimes with refere=
nces (and perhaps also const pointers?).&nbsp; I think it would only be use=
ful to do this for function parameters, return values, and class/struct mem=
bers.&nbsp; I don't know what the best syntax would be.<br>- Constexpr func=
tions would be used for metaprogramming using lifetimes.&nbsp; A default co=
nstructed lifetime would refer to an empty lifetime.&nbsp; We would also ne=
ed a builtin operation returning a new lifetime object corresponding to the=
 union of two lifetime objects.<br><br>It is not clear how these lifetime p=
arameters should interact with class identity, but it seems necessary to su=
pport composability.<br><br>Perhaps there could be some form of automatic l=
ifetime deduction as well.<br></div>

<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 />

------=_Part_24_1304299547.1412879638281--

.