Topic: auto with copy in expression
Author: Michael AV <donnerdose@googlemail.com>
Date: Tue, 24 Sep 2013 05:35:58 -0700 (PDT)
Raw View
------=_Part_1993_19940371.1380026158409
Content-Type: text/plain; charset=ISO-8859-1
Hi,
I would like to create a copy of the return value of a function. This
result shall be passed to another function. The two-line solution would be:
auto result = foo();
bar(result);
bar expects a reference and foo returns a reference. However, in this case
it is crucial for bar to only receive a copy because (for this specific
result argument), bar changes what foo delivers. That does not mean,
however, that bar does always change it's argument.
So, basically I just need a copy and would like to use it within an
expression. The most intuitive syntax for me would be:
bar(auto(foo()));
which does not work at the moment (as tested with the - clearly obsolete -
VS2010).
I tried searching this group and thinking about why this syntax does not
make sense but did not come to any result.
What do you think?
Thank you very much and best regards,
Michael
--
---
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_1993_19940371.1380026158409
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>Hi,</div><div><br></div><div>I would like to create a=
copy of the return value of a function. This result shall be passed to ano=
ther function. The two-line solution would be:</div><div><br></div><div><di=
v class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); bord=
er: 1px solid rgb(187, 187, 187); word-wrap: break-word;"><code class=3D"pr=
ettyprint"><div class=3D"subprettyprint"><div class=3D"prettyprint" style=
=3D"background-color: rgb(250, 250, 250); border: 1px solid rgb(187, 187, 1=
87); word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subp=
rettyprint"><font color=3D"#660066">auto result =3D foo();<br>bar(result);<=
/font></div></code></div></div></code></div><br>bar expects a reference and=
foo returns a reference. However, in this case it is crucial for bar to on=
ly receive a copy because (for this specific result argument), bar changes =
what foo delivers. That does not mean, however, that bar does always change=
it's argument.</div><div><br></div><div>So, basically I just need a copy a=
nd would like to use it within an expression. The most intuitive syntax for=
me would be:</div><div><br></div><div><div class=3D"prettyprint" style=3D"=
background-color: rgb(250, 250, 250); border: 1px solid rgb(187, 187, 187);=
word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprett=
yprint"><font color=3D"#660066">bar(auto(foo()));</font></div></code></div>=
<br>which does not work at the moment (as tested with the - clearly obsolet=
e - VS2010).</div><div><br></div><div>I tried searching this group and thin=
king about why this syntax does not make sense but did not come to any resu=
lt.</div><div><br></div><div>What do you think?</div><div><br></div><div>Th=
ank you very much and best regards,</div><div>Michael</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" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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_1993_19940371.1380026158409--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Tue, 1 Oct 2013 18:23:41 +0300
Raw View
--001a11c22634a5a7dc04e7af8951
Content-Type: text/plain; charset=ISO-8859-1
On 24 September 2013 15:35, Michael AV <donnerdose@googlemail.com> wrote:
> Hi,
>
> I would like to create a copy of the return value of a function. This
> result shall be passed to another function. The two-line solution would be:
>
> auto result = foo();
> bar(result);
>
> bar expects a reference and foo returns a reference. However, in this case
> it is crucial for bar to only receive a copy because (for this specific
> result argument), bar changes what foo delivers. That does not mean,
> however, that bar does always change it's argument.
>
> So, basically I just need a copy and would like to use it within an
> expression. The most intuitive syntax for me would be:
>
> bar(auto(foo()));
>
> which does not work at the moment (as tested with the - clearly obsolete -
> VS2010).
>
> I tried searching this group and thinking about why this syntax does not
> make sense but did not come to any result.
>
> What do you think?
>
>
>
bar([](){auto x(foo()); return x;}());
You can't create temporaries with auto, as far as I understand the language
rules.
Also, in whichever way this temporary is created, bar() needs to accept an
rvalue
reference, since lvalue references can't bind to temporaries.
--
---
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/.
--001a11c22634a5a7dc04e7af8951
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><br><div class=3D"gmail=
_quote">On 24 September 2013 15:35, Michael AV <span dir=3D"ltr"><<a hre=
f=3D"mailto:donnerdose@googlemail.com" target=3D"_blank">donnerdose@googlem=
ail.com</a>></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>Hi,</div><div><br></di=
v><div>I would like to create a copy of the return value of a function. Thi=
s result shall be passed to another function. The two-line solution would b=
e:</div>
<div><br></div><div><div style=3D"background-color:rgb(250,250,250);border:=
1px solid rgb(187,187,187);word-wrap:break-word"><code><div><div style=3D"b=
ackground-color:rgb(250,250,250);border:1px solid rgb(187,187,187);word-wra=
p:break-word">
<code><div><font color=3D"#660066">auto result =3D foo();<br>bar(result);</=
font></div></code></div></div></code></div><br>bar expects a reference and =
foo returns a reference. However, in this case it is crucial for bar to onl=
y receive a copy because (for this specific result argument), bar changes w=
hat foo delivers. That does not mean, however, that bar does always change =
it's argument.</div>
<div><br></div><div>So, basically I just need a copy and would like to use =
it within an expression. The most intuitive syntax for me would be:</div><d=
iv><br></div><div><div style=3D"background-color:rgb(250,250,250);border:1p=
x solid rgb(187,187,187);word-wrap:break-word">
<code><div><font color=3D"#660066">bar(auto(foo()));</font></div></code></d=
iv><br>which does not work at the moment (as tested with the - clearly obso=
lete - VS2010).</div><div><br></div><div>I tried searching this group and t=
hinking about why this syntax does not make sense but did not come to any r=
esult.</div>
<div><br></div><div>What do you think?</div><div><br><br></div></div></bloc=
kquote><div><br></div><div>bar([](){auto x(foo()); return x;}()); <br></div=
></div><br></div><div class=3D"gmail_extra">You can't create temporarie=
s with auto, as far as I understand the language rules.<br>
</div><div class=3D"gmail_extra">Also, in whichever way this temporary is c=
reated, bar() needs to accept an rvalue<br>reference, since lvalue referenc=
es can't bind to temporaries.<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" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />
--001a11c22634a5a7dc04e7af8951--
.
Author: =?UTF-8?Q?Klaim_=2D_Jo=C3=ABl_Lamotte?= <mjklaim@gmail.com>
Date: Tue, 1 Oct 2013 18:04:23 +0200
Raw View
--047d7b33d1762f227b04e7b01b3d
Content-Type: text/plain; charset=ISO-8859-1
If my memory is correct, the proposal for decltype(auto) should fix the
issue?
That is:
decltype(auto) result = foo(); // result is always a copy
I'm not totally sure though.
--
---
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/.
--047d7b33d1762f227b04e7b01b3d
Content-Type: text/html; charset=ISO-8859-1
<div dir="ltr">If my memory is correct, the proposal for decltype(auto) should fix the issue?<div>That is:</div><div><br></div><div>decltype(auto) result = foo(); // result is always a copy</div><div><br></div><div class="gmail_extra">
I'm not totally sure though.</div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href="http://groups.google.com/a/isocpp.org/group/std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/</a>.<br />
--047d7b33d1762f227b04e7b01b3d--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Tue, 1 Oct 2013 19:14:49 +0300
Raw View
--001a11c25b487ec5ad04e7b04072
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
On 1 October 2013 19:04, Klaim - Jo=EBl Lamotte <mjklaim@gmail.com> wrote:
> If my memory is correct, the proposal for decltype(auto) should fix the
> issue?
> That is:
>
> decltype(auto) result =3D foo(); // result is always a copy
>
> I'm not totally sure though.
>
>
>
>
That's the opposite. auto result =3D whatever is always a value, never a
reference.
decltype(auto) result =3D whatever may be a reference.
auto& result =3D whatever is always a reference.
None of these help since auto cannot appear in an expression yielding a
temporary.
--=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/.
--001a11c25b487ec5ad04e7b04072
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><br><div class=3D"gmail=
_quote">On 1 October 2013 19:04, Klaim - Jo=EBl Lamotte <span dir=3D"ltr">&=
lt;<a href=3D"mailto:mjklaim@gmail.com" target=3D"_blank">mjklaim@gmail.com=
</a>></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr">If my memory is correct, th=
e proposal for decltype(auto) should fix the issue?<div>That is:</div><div>=
<br>
</div><div>decltype(auto) result =3D foo(); // result is always a copy</div=
><div><br></div><div class=3D"gmail_extra">
I'm not totally sure though.</div></div><div class=3D"HOEnZb"><div clas=
s=3D"h5">
<p></p>
<br><br></div></div></blockquote><div><br></div><div>That's the opposit=
e. auto result =3D whatever is always a value, never a reference.<br></div>=
<div>decltype(auto) result =3D=A0 whatever may be a reference.<br></div><di=
v>
auto& result =3D whatever is always a reference.<br><br></div><div>None=
of these help since auto cannot appear in an expression yielding a tempora=
ry.<br></div></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" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />
--001a11c25b487ec5ad04e7b04072--
.
Author: Zhihao Yuan <zy@miator.net>
Date: Tue, 1 Oct 2013 12:35:16 -0400
Raw View
On Tue, Sep 24, 2013 at 8:35 AM, Michael AV <donnerdose@googlemail.com> wrote:
> bar(auto(foo()));
You just need a copy right? A quick test:
#include <iostream>
struct A {
A() {}
A(A const&) {
std::cout << "copied" << std::endl;
}
A(A&&) {
std::cout << "moved" << std::endl;
}
};
A& foo() {
static A a;
return a;
}
void bar(A const& a)
{}
template <typename T>
T make_a_copy(T const& t) {
return t;
}
int main() {
bar(foo());
bar(make_a_copy(foo()));
}
--
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
___________________________________________________
4BSD -- http://4bsd.biz/
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: =?UTF-8?Q?Klaim_=2D_Jo=C3=ABl_Lamotte?= <mjklaim@gmail.com>
Date: Tue, 1 Oct 2013 19:12:12 +0200
Raw View
--089e01227b7cbe40bd04e7b10da4
Content-Type: text/plain; charset=ISO-8859-1
On Tue, Oct 1, 2013 at 6:14 PM, Ville Voutilainen <
ville.voutilainen@gmail.com> wrote:
> That's the opposite. auto result = whatever is always a value, never a
> reference.
> decltype(auto) result = whatever may be a reference.
> auto& result = whatever is always a reference.
>
> None of these help since auto cannot appear in an expression yielding a
> temporary.
>
Indeed, thanks for the correction.
--
---
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/.
--089e01227b7cbe40bd04e7b10da4
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">=
On Tue, Oct 1, 2013 at 6:14 PM, Ville Voutilainen <span dir=3D"ltr"><<a =
href=3D"mailto:ville.voutilainen@gmail.com" target=3D"_blank">ville.voutila=
inen@gmail.com</a>></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div>That's the opposite. auto result =
=3D whatever is always a value, never a reference.<br></div><div>decltype(a=
uto) result =3D=A0 whatever may be a reference.<br>
</div><div>
auto& result =3D whatever is always a reference.<br><br></div><div>None=
of these help since auto cannot appear in an expression yielding a tempora=
ry.</div></blockquote></div><br>Indeed, thanks for the correction.</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" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />
--089e01227b7cbe40bd04e7b10da4--
.
Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@gmail.com>
Date: Tue, 1 Oct 2013 19:14:08 +0200
Raw View
2013/10/1 Zhihao Yuan <zy@miator.net>:
> On Tue, Sep 24, 2013 at 8:35 AM, Michael AV <donnerdose@googlemail.com> wrote:
>> bar(auto(foo()));
>
> You just need a copy right? A quick test:
>
> #include <iostream>
>
> struct A {
> A() {}
> A(A const&) {
> std::cout << "copied" << std::endl;
> }
> A(A&&) {
> std::cout << "moved" << std::endl;
> }
> };
>
> A& foo() {
> static A a;
> return a;
> }
>
> void bar(A const& a)
> {}
>
> template <typename T>
> T make_a_copy(T const& t) {
> return t;
> }
Personally I would like to see decay_copy standardized:
template <class T> typename decay<T>::type decay_copy(T&& v)
{ return std::forward<T>(v); }
(See also
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3255.html
)
- Daniel
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Zhihao Yuan <zy@miator.net>
Date: Tue, 1 Oct 2013 13:48:31 -0400
Raw View
On Tue, Oct 1, 2013 at 1:14 PM, Daniel Kr=FCgler
<daniel.kruegler@gmail.com> wrote:
> Personally I would like to see decay_copy standardized:
>
> template <class T> typename decay<T>::type decay_copy(T&& v)
> { return std::forward<T>(v); }
When you say "decay" 'I get an icy feeling down my spine'...
I'm fine if the array and the function cases just do not compile.
The one in threads is fine, but here we explicitly ask for a copy.
--=20
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
___________________________________________________
4BSD -- http://4bsd.biz/
--=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/.
.
Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@gmail.com>
Date: Tue, 1 Oct 2013 20:01:30 +0200
Raw View
2013/10/1 Zhihao Yuan <zy@miator.net>:
> On Tue, Oct 1, 2013 at 1:14 PM, Daniel Kr=FCgler
> <daniel.kruegler@gmail.com> wrote:
>> Personally I would like to see decay_copy standardized:
>>
>> template <class T> typename decay<T>::type decay_copy(T&& v)
>> { return std::forward<T>(v); }
>
> When you say "decay" 'I get an icy feeling down my spine'...
Well, you seem to have a different use case as the OP then (at least
as I understood it, because he explicitly referred to auto semantics
of return type deduction).
> I'm fine if the array and the function cases just do not compile.
The effect of "auto" on function types and arrays is the same as using
decay_copy (except for braced init lists). The OP was asking for
something comparable. I think that decay_copy is the answer to that
question.
> The one in threads is fine, but here we explicitly ask for a copy.
It depends on your use-case. auto return types and auto as parameter
type in polymorphic closures behave quite similar to decay_copy.
The name of decay_copy is clear. If this is not what you need, don't use it=
..
- Daniel
--=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/.
.
Author: Richard Smith <richard@metafoo.co.uk>
Date: Tue, 1 Oct 2013 15:12:17 -0700
Raw View
--20cf3079b5f2eed31704e7b53efd
Content-Type: text/plain; charset=ISO-8859-1
On Tue, Oct 1, 2013 at 8:23 AM, Ville Voutilainen <
ville.voutilainen@gmail.com> wrote:
> On 24 September 2013 15:35, Michael AV <donnerdose@googlemail.com> wrote:
>
>> Hi,
>>
>> I would like to create a copy of the return value of a function. This
>> result shall be passed to another function. The two-line solution would be:
>>
>> auto result = foo();
>> bar(result);
>>
>> bar expects a reference and foo returns a reference. However, in this
>> case it is crucial for bar to only receive a copy because (for this
>> specific result argument), bar changes what foo delivers. That does not
>> mean, however, that bar does always change it's argument.
>>
>> So, basically I just need a copy and would like to use it within an
>> expression. The most intuitive syntax for me would be:
>>
>> bar(auto(foo()));
>>
>> which does not work at the moment (as tested with the - clearly obsolete
>> - VS2010).
>>
>> I tried searching this group and thinking about why this syntax does not
>> make sense but did not come to any result.
>>
>> What do you think?
>>
>>
>>
> bar([](){auto x(foo()); return x;}());
>
> You can't create temporaries with auto, as far as I understand the
> language rules.
> Also, in whichever way this temporary is created, bar() needs to accept an
> rvalue
> reference, since lvalue references can't bind to temporaries.
>
Right. If 'bar' is intended to modify the caller's object, it should not
accept a temporary. Given that, why not:
auto result = foo();
auto bar_value = result;
bar(bar_value);
--
---
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/.
--20cf3079b5f2eed31704e7b53efd
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tue, Oct 1, 2013 at 8:23 AM, Ville Voutilainen <span di=
r=3D"ltr"><<a href=3D"mailto:ville.voutilainen@gmail.com" target=3D"_bla=
nk">ville.voutilainen@gmail.com</a>></span> wrote:<br><div class=3D"gmai=
l_extra">
<div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margi=
n:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">=
<span style=3D"color:rgb(80,0,80)">On 24 September 2013 15:35, Michael AV <=
/span><span dir=3D"ltr" style=3D"color:rgb(80,0,80)"><<a href=3D"mailto:=
donnerdose@googlemail.com" target=3D"_blank">donnerdose@googlemail.com</a>&=
gt;</span><span style=3D"color:rgb(80,0,80)"> wrote:</span><br>
<div class=3D"gmail_extra"><div class=3D"gmail_quote"><div class=3D"im">
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>Hi,</div><div><br></di=
v><div>I would like to create a copy of the return value of a function. Thi=
s result shall be passed to another function. The two-line solution would b=
e:</div>
<div><br></div><div><div style=3D"background-color:rgb(250,250,250);border:=
1px solid rgb(187,187,187);word-wrap:break-word"><code><div><div style=3D"b=
ackground-color:rgb(250,250,250);border:1px solid rgb(187,187,187);word-wra=
p:break-word">
<code><div><font color=3D"#660066">auto result =3D foo();<br>bar(result);</=
font></div></code></div></div></code></div><br>bar expects a reference and =
foo returns a reference. However, in this case it is crucial for bar to onl=
y receive a copy because (for this specific result argument), bar changes w=
hat foo delivers. That does not mean, however, that bar does always change =
it's argument.</div>
<div><br></div><div>So, basically I just need a copy and would like to use =
it within an expression. The most intuitive syntax for me would be:</div><d=
iv><br></div><div><div style=3D"background-color:rgb(250,250,250);border:1p=
x solid rgb(187,187,187);word-wrap:break-word">
<code><div><font color=3D"#660066">bar(auto(foo()));</font></div></code></d=
iv><br>which does not work at the moment (as tested with the - clearly obso=
lete - VS2010).</div><div><br></div><div>I tried searching this group and t=
hinking about why this syntax does not make sense but did not come to any r=
esult.</div>
<div><br></div><div>What do you think?</div><div><br><br></div></div></bloc=
kquote><div><br></div></div><div>bar([](){auto x(foo()); return x;}()); <br=
></div></div><br></div><div class=3D"gmail_extra">You can't create temp=
oraries with auto, as far as I understand the language rules.<br>
</div><div class=3D"gmail_extra">Also, in whichever way this temporary is c=
reated, bar() needs to accept an rvalue<br>reference, since lvalue referenc=
es can't bind to temporaries.</div></div></blockquote><div><br></div>
<div>Right. If 'bar' is intended to modify the caller's object,=
it should not accept a temporary. Given that, why not:</div><div><br></div=
><div>auto result =3D foo();</div><div>auto bar_value =3D result;</div><div=
>
bar(bar_value);</div></div></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" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />
--20cf3079b5f2eed31704e7b53efd--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 2 Oct 2013 07:09:55 +0300
Raw View
--f46d043d6557e9dad904e7ba3d2c
Content-Type: text/plain; charset=ISO-8859-1
On 2 October 2013 01:12, Richard Smith <richard@metafoo.co.uk> wrote:
> On Tue, Oct 1, 2013 at 8:23 AM, Ville Voutilainen <
> ville.voutilainen@gmail.com> wrote:
>
>> On 24 September 2013 15:35, Michael AV <donnerdose@googlemail.com> wrote:
>>
>>> Hi,
>>>
>>> I would like to create a copy of the return value of a function. This
>>> result shall be passed to another function. The two-line solution would be:
>>>
>>> auto result = foo();
>>> bar(result);
>>>
>>> bar expects a reference and foo returns a reference. However, in this
>>> case it is crucial for bar to only receive a copy because (for this
>>> specific result argument), bar changes what foo delivers. That does not
>>> mean, however, that bar does always change it's argument.
>>>
>>> So, basically I just need a copy and would like to use it within an
>>> expression. The most intuitive syntax for me would be:
>>>
>>> bar(auto(foo()));
>>>
>>> which does not work at the moment (as tested with the - clearly obsolete
>>> - VS2010).
>>>
>>> I tried searching this group and thinking about why this syntax does not
>>> make sense but did not come to any result.
>>>
>>> What do you think?
>>>
>>>
>>>
>> bar([](){auto x(foo()); return x;}());
>>
>> You can't create temporaries with auto, as far as I understand the
>> language rules.
>> Also, in whichever way this temporary is created, bar() needs to accept
>> an rvalue
>> reference, since lvalue references can't bind to temporaries.
>>
>
> Right. If 'bar' is intended to modify the caller's object, it should not
> accept a temporary. Given that, why not:
>
> auto result = foo();
> auto bar_value = result;
> bar(bar_value);
>
>
>
>
How's that different from
auto result = foo();
bar(result);
?
And it's still not usable in an expression. Unless wickedly wrapped in a
lambda, like I did
above.
--
---
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/.
--f46d043d6557e9dad904e7ba3d2c
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><br><div class=3D"gmail=
_quote">On 2 October 2013 01:12, Richard Smith <span dir=3D"ltr"><<a hre=
f=3D"mailto:richard@metafoo.co.uk" target=3D"_blank">richard@metafoo.co.uk<=
/a>></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div class=3D"h5">On T=
ue, Oct 1, 2013 at 8:23 AM, Ville Voutilainen <span dir=3D"ltr"><<a href=
=3D"mailto:ville.voutilainen@gmail.com" target=3D"_blank">ville.voutilainen=
@gmail.com</a>></span> wrote:<br>
</div></div><div class=3D"gmail_extra">
<div class=3D"gmail_quote"><div><div class=3D"h5"><blockquote class=3D"gmai=
l_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left=
:1ex"><div dir=3D"ltr"><span style=3D"color:rgb(80,0,80)">On 24 September 2=
013 15:35, Michael AV </span><span dir=3D"ltr" style=3D"color:rgb(80,0,80)"=
><<a href=3D"mailto:donnerdose@googlemail.com" target=3D"_blank">donnerd=
ose@googlemail.com</a>></span><span style=3D"color:rgb(80,0,80)"> wrote:=
</span><br>
<div class=3D"gmail_extra"><div class=3D"gmail_quote"><div>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>Hi,</div><div><br></di=
v><div>I would like to create a copy of the return value of a function. Thi=
s result shall be passed to another function. The two-line solution would b=
e:</div>
<div><br></div><div><div style=3D"background-color:rgb(250,250,250);border:=
1px solid rgb(187,187,187);word-wrap:break-word"><code><div><div style=3D"b=
ackground-color:rgb(250,250,250);border:1px solid rgb(187,187,187);word-wra=
p:break-word">
<code><div><font color=3D"#660066">auto result =3D foo();<br>bar(result);</=
font></div></code></div></div></code></div><br>bar expects a reference and =
foo returns a reference. However, in this case it is crucial for bar to onl=
y receive a copy because (for this specific result argument), bar changes w=
hat foo delivers. That does not mean, however, that bar does always change =
it's argument.</div>
<div><br></div><div>So, basically I just need a copy and would like to use =
it within an expression. The most intuitive syntax for me would be:</div><d=
iv><br></div><div><div style=3D"background-color:rgb(250,250,250);border:1p=
x solid rgb(187,187,187);word-wrap:break-word">
<code><div><font color=3D"#660066">bar(auto(foo()));</font></div></code></d=
iv><br>which does not work at the moment (as tested with the - clearly obso=
lete - VS2010).</div><div><br></div><div>I tried searching this group and t=
hinking about why this syntax does not make sense but did not come to any r=
esult.</div>
<div><br></div><div>What do you think?</div><div><br><br></div></div></bloc=
kquote><div><br></div></div><div>bar([](){auto x(foo()); return x;}()); <br=
></div></div><br></div><div class=3D"gmail_extra">You can't create temp=
oraries with auto, as far as I understand the language rules.<br>
</div><div class=3D"gmail_extra">Also, in whichever way this temporary is c=
reated, bar() needs to accept an rvalue<br>reference, since lvalue referenc=
es can't bind to temporaries.</div></div></blockquote><div><br></div>
</div></div><div>Right. If 'bar' is intended to modify the caller&#=
39;s object, it should not accept a temporary. Given that, why not:</div><d=
iv><br></div><div>auto result =3D foo();</div><div>auto bar_value =3D resul=
t;</div>
<div>
bar(bar_value);</div></div></div></div><div class=3D"HOEnZb"><div class=3D"=
h5">
<p></p>
<br><br></div></div></blockquote><div><br></div><div>How's that differe=
nt from<br>auto result =3D foo();<br></div><div>bar(result);<br>?<br><br></=
div><div>And it's still not usable in an expression. Unless wickedly wr=
apped in a lambda, like I did<br>
above.<br></div></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" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />
--f46d043d6557e9dad904e7ba3d2c--
.
Author: Richard Smith <richard@metafoo.co.uk>
Date: Wed, 2 Oct 2013 12:16:59 -0700
Raw View
--20cf307f3246d9d65904e7c6e9f3
Content-Type: text/plain; charset=ISO-8859-1
On Tue, Oct 1, 2013 at 9:09 PM, Ville Voutilainen <
ville.voutilainen@gmail.com> wrote:
>
>
>
> On 2 October 2013 01:12, Richard Smith <richard@metafoo.co.uk> wrote:
>
>> On Tue, Oct 1, 2013 at 8:23 AM, Ville Voutilainen <
>> ville.voutilainen@gmail.com> wrote:
>>
>>> On 24 September 2013 15:35, Michael AV <donnerdose@googlemail.com>wrote:
>>>
>>>> Hi,
>>>>
>>>> I would like to create a copy of the return value of a function. This
>>>> result shall be passed to another function. The two-line solution would be:
>>>>
>>>> auto result = foo();
>>>> bar(result);
>>>>
>>>> bar expects a reference and foo returns a reference. However, in this
>>>> case it is crucial for bar to only receive a copy because (for this
>>>> specific result argument), bar changes what foo delivers. That does not
>>>> mean, however, that bar does always change it's argument.
>>>>
>>>> So, basically I just need a copy and would like to use it within an
>>>> expression. The most intuitive syntax for me would be:
>>>>
>>>> bar(auto(foo()));
>>>>
>>>> which does not work at the moment (as tested with the - clearly
>>>> obsolete - VS2010).
>>>>
>>>> I tried searching this group and thinking about why this syntax does
>>>> not make sense but did not come to any result.
>>>>
>>>> What do you think?
>>>>
>>>>
>>>>
>>> bar([](){auto x(foo()); return x;}());
>>>
>>> You can't create temporaries with auto, as far as I understand the
>>> language rules.
>>> Also, in whichever way this temporary is created, bar() needs to accept
>>> an rvalue
>>> reference, since lvalue references can't bind to temporaries.
>>>
>>
>> Right. If 'bar' is intended to modify the caller's object, it should not
>> accept a temporary. Given that, why not:
>>
>> auto result = foo();
>> auto bar_value = result;
>> bar(bar_value);
>>
>>
>>
>>
> How's that different from
> auto result = foo();
> bar(result);
> ?
>
> And it's still not usable in an expression. Unless wickedly wrapped in a
> lambda, like I did
> above.
>
Sorry, I misread the question =)
> --
>
> ---
> 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/.
>
--
---
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/.
--20cf307f3246d9d65904e7c6e9f3
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tue, Oct 1, 2013 at 9:09 PM, Ville Voutilainen <span di=
r=3D"ltr"><<a href=3D"mailto:ville.voutilainen@gmail.com" target=3D"_bla=
nk">ville.voutilainen@gmail.com</a>></span> wrote:<br><div class=3D"gmai=
l_extra">
<div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margi=
n:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">=
<br><div class=3D"gmail_extra"><br><br><div class=3D"gmail_quote"><div><div=
class=3D"h5">
On 2 October 2013 01:12, Richard Smith <span dir=3D"ltr"><<a href=3D"mai=
lto:richard@metafoo.co.uk" target=3D"_blank">richard@metafoo.co.uk</a>><=
/span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div>On Tue, Oct 1, 20=
13 at 8:23 AM, Ville Voutilainen <span dir=3D"ltr"><<a href=3D"mailto:vi=
lle.voutilainen@gmail.com" target=3D"_blank">ville.voutilainen@gmail.com</a=
>></span> wrote:<br>
</div></div><div class=3D"gmail_extra">
<div class=3D"gmail_quote"><div><div><blockquote class=3D"gmail_quote" styl=
e=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div di=
r=3D"ltr"><span style=3D"color:rgb(80,0,80)">On 24 September 2013 15:35, Mi=
chael AV </span><span dir=3D"ltr" style=3D"color:rgb(80,0,80)"><<a href=
=3D"mailto:donnerdose@googlemail.com" target=3D"_blank">donnerdose@googlema=
il.com</a>></span><span style=3D"color:rgb(80,0,80)"> wrote:</span><br>
<div class=3D"gmail_extra"><div class=3D"gmail_quote"><div>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>Hi,</div><div><br></di=
v><div>I would like to create a copy of the return value of a function. Thi=
s result shall be passed to another function. The two-line solution would b=
e:</div>
<div><br></div><div><div style=3D"background-color:rgb(250,250,250);border:=
1px solid rgb(187,187,187);word-wrap:break-word"><code><div><div style=3D"b=
ackground-color:rgb(250,250,250);border:1px solid rgb(187,187,187);word-wra=
p:break-word">
<code><div><font color=3D"#660066">auto result =3D foo();<br>bar(result);</=
font></div></code></div></div></code></div><br>bar expects a reference and =
foo returns a reference. However, in this case it is crucial for bar to onl=
y receive a copy because (for this specific result argument), bar changes w=
hat foo delivers. That does not mean, however, that bar does always change =
it's argument.</div>
<div><br></div><div>So, basically I just need a copy and would like to use =
it within an expression. The most intuitive syntax for me would be:</div><d=
iv><br></div><div><div style=3D"background-color:rgb(250,250,250);border:1p=
x solid rgb(187,187,187);word-wrap:break-word">
<code><div><font color=3D"#660066">bar(auto(foo()));</font></div></code></d=
iv><br>which does not work at the moment (as tested with the - clearly obso=
lete - VS2010).</div><div><br></div><div>I tried searching this group and t=
hinking about why this syntax does not make sense but did not come to any r=
esult.</div>
<div><br></div><div>What do you think?</div><div><br><br></div></div></bloc=
kquote><div><br></div></div><div>bar([](){auto x(foo()); return x;}()); <br=
></div></div><br></div><div class=3D"gmail_extra">You can't create temp=
oraries with auto, as far as I understand the language rules.<br>
</div><div class=3D"gmail_extra">Also, in whichever way this temporary is c=
reated, bar() needs to accept an rvalue<br>reference, since lvalue referenc=
es can't bind to temporaries.</div></div></blockquote><div><br></div>
</div></div><div>Right. If 'bar' is intended to modify the caller&#=
39;s object, it should not accept a temporary. Given that, why not:</div><d=
iv><br></div><div>auto result =3D foo();</div><div>auto bar_value =3D resul=
t;</div>
<div>
bar(bar_value);</div></div></div></div><div><div>
<p></p>
<br><br></div></div></blockquote><div><br></div></div></div><div>How's =
that different from<br>auto result =3D foo();<br></div><div>bar(result);<br=
>?<br><br></div><div>And it's still not usable in an expression. Unless=
wickedly wrapped in a lambda, like I did<br>
above.</div></div></div></div></blockquote><div><br></div><div>Sorry, I mis=
read the question =3D)</div><div>=A0</div><blockquote class=3D"gmail_quote"=
style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><d=
iv class=3D"HOEnZb">
<div class=3D"h5">
<p></p>
-- <br>
=A0<br>
--- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals%2Bunsubscribe@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>
</div></div></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" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />
--20cf307f3246d9d65904e7c6e9f3--
.