Topic: Different style of function "pointer": lifting an
Author: Justin Bassett <jbassett271@gmail.com>
Date: Fri, 14 Jul 2017 22:29:29 -0700 (PDT)
Raw View
------=_Part_0_611284157.1500096569133
Content-Type: multipart/alternative;
boundary="----=_Part_1_1896248956.1500096569148"
------=_Part_1_1896248956.1500096569148
Content-Type: text/plain; charset="UTF-8"
This seems to be almost the same as Suggesting a syntax for wraping
overload set
<https://groups.google.com/a/isocpp.org/d/msg/std-proposals/lOTFtnNRahY/yustd1j6BgAJ>
.
Currently in C++, we can get a function pointer with &ns::foo or ns::foo. The
problem with this is that, if foo is overloaded, it fails to compile as it
actually needs to produce a pointer to a concrete function. I find this
unintuitive. To get the behavior I would expect, one would need to write:
[](auto&&... args) { return ns::foo(std::forward<decltype(args)>(args)...);
}
Or in the truly general case:
[](auto&&... args) noexcept(noexcept(ns::foo(std::forward<decltype(args)>(
args)...)))
-> decltype(ns::foo(std::forward<decltype(args)>(args)...))
{
return ns::foo(std::forward<decltype(args)>(args)...);
}
Or, using Barry's Abbreviated Lambdas
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0573r0.html>:
[](args...) => ns::foo(>>args...)
In that paper, it was mentioned that there is an idea floating around to
make this:
[]ns::foo
I think this should be added to C++.
Furthermore, if Make Pointers to Members Callable
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0312r1.html> happens,
it makes sense to have the corresponding thing for member pointers:
[]ns::Class::member
Which would be roughly equivalent to:
[](auto&& cls, auto&&... args) {
static_assert(std::is_same_v<ns::Class, std::decay_t<decltype(cls)>>);
return std::forward<decltype(cls)>(cls).member(std::forward<decltype(
args)>(args)...);
}
But it would make sense to allow the cls parameter to be the same as in
std::invoke (as in the Make Pointers to Members Callable paper). That is,
if cls were actually a ns::Class*, it would work, as well as a
std::reference_wrapper<ns::Class> and the rest of the invoke protocol.
This has an immediate benefit: you can make this type of function reference
to standard library objects. &std::string::size is illegal, as the standard
library is allowed to have default arguments, but []std::string::size would
be legal.
There are possible drawbacks. For one, what should the following be:
void foo() {}
int main() {
auto foo = []{};
auto bar = []foo;
}
Should it capture foo, call the foo function, or do something else? I'd
suggest that it would call the foo function, and that if the user wanted to
capture it would be:
int main() {
auto foo = []{};
auto bar = [foo]foo; // or [&foo]foo to capture by reference
}
But that might not be feasible.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/438053e9-d818-4269-855a-abb08ed3a556%40isocpp.org.
------=_Part_1_1896248956.1500096569148
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>This seems to be almost the same as=C2=A0<a href=3D"h=
ttps://groups.google.com/a/isocpp.org/d/msg/std-proposals/lOTFtnNRahY/yustd=
1j6BgAJ">Suggesting a syntax for wraping overload set</a>=C2=A0.</div><div>=
<br></div>Currently in C++, we can get a function pointer with <font face=
=3D"courier new, monospace">&ns::foo</font><font face=3D"arial, sans-se=
rif">=C2=A0or </font><font face=3D"courier new, monospace">ns::foo.=C2=A0</=
font>The problem with this is that, if <font face=3D"courier new, monospace=
">foo</font> is overloaded, it fails to compile=C2=A0as it actually needs t=
o produce a pointer to a concrete function. I find this unintuitive. To get=
the behavior I would expect, one would need to write:<div><div><br></div><=
div><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250=
); border-color: rgb(187, 187, 187); border-style: solid; border-width: 1px=
; word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subpret=
typrint"><span style=3D"color: #660;" class=3D"styled-by-prettify">[](</spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">&&...</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> args</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">return</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> ns</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">foo=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">std</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">forward</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">decltype</span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify">args</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">)>(</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify">args</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">)...);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div>=
</code></div><br>Or in the truly general case:</div><div><br></div><div><di=
v class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); bord=
er-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-=
wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint=
"><font color=3D"#660066"><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">[](</span><span style=3D"color: #008;" class=3D"styled-by-prettify=
">auto</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
;&...</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
args</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> noexcept</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">noexcept</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">ns</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">foo</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify">std</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">forward=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">decltype</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">args</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">)>(</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">args</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">)...)))</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">-></span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">decltype</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">ns</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">foo</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">std</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">forward</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify"><</span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
decltype</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify">args</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">)>(</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">args</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">)...))</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">return</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"> ns</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">foo</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">forward</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">decltype</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify">args</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">)>(</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify">args</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">)...);</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">}</span></font></div></code></div><div><br></div>Or, using <a=
href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0573r0.ht=
ml">Barry's Abbreviated Lambdas</a>:</div><div><br></div><div><div clas=
s=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-col=
or: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: =
break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><spa=
n style=3D"color: rgb(0, 0, 0); font-size: medium; text-align: justify; whi=
te-space: pre;"><span style=3D"color: #660;" class=3D"styled-by-prettify">[=
](</span><span style=3D"color: #000;" class=3D"styled-by-prettify">args</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">...)</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">=3D></span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> ns</span><span style=3D"color:=
#660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify">foo</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(>></span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">args</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">...)</span></span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br></span></div></code></div><br>In that paper, it was =
mentioned that there is an idea floating around to make this:</div><div><br=
></div><div><div class=3D"prettyprint" style=3D"background-color: rgb(250, =
250, 250); border-color: rgb(187, 187, 187); border-style: solid; border-wi=
dth: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D=
"subprettyprint"><font color=3D"#660066"><span style=3D"color: #660;" class=
=3D"styled-by-prettify">[]</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">ns</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
foo</span></font></div></code></div><br>I think this should be added to C++=
..</div><div><br></div><div>Furthermore, if <a href=3D"http://www.open-std.o=
rg/jtc1/sc22/wg21/docs/papers/2017/p0312r1.html">Make Pointers to Members C=
allable</a>=C2=A0happens, it makes sense to have the corresponding thing fo=
r member pointers:</div><div><br></div><div><div class=3D"prettyprint" styl=
e=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187)=
; border-style: solid; border-width: 1px; word-wrap: break-word;"><code cla=
ss=3D"prettyprint"><div class=3D"subprettyprint"><font color=3D"#660066"><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">[]</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">ns</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #606=
;" class=3D"styled-by-prettify">Class</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify">member</span></font></div></code></div><br>Which would b=
e roughly equivalent to:</div></div><div><br></div><div><div class=3D"prett=
yprint" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(18=
7, 187, 187); border-style: solid; border-width: 1px; word-wrap: break-word=
;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D=
"color: #660;" class=3D"styled-by-prettify">[](</span><span style=3D"color:=
#008;" class=3D"styled-by-prettify">auto</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">&&</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> cls</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">auto</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>&&...</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> args</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">static_assert</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify">std</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">is_same_v</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify"><</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">ns</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">::</span><span style=3D"color: #606;" class=3D"styled-by=
-prettify">Class</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> st=
d</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">decay_t</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">decltype</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">cls</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">)>>);</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></span><font color=3D"#000000"><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">=C2=A0 =C2=A0 </span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">return</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify">forward</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify"><</span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">decltype</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">cls</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">)>(</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify">cls</span><span style=3D"color: #660;" class=3D"styled-by-prettify">).=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">member</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify">std</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">forward</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #008;"=
class=3D"styled-by-prettify">decltype</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify">args</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">)>(</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">args</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">)...);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></fon=
t></div></code></div><div><br></div>But it would make sense to allow the <f=
ont face=3D"courier new, monospace">cls</font> parameter to be the same as =
in <font face=3D"courier new, monospace">std::invoke</font> (as in the Make=
Pointers to Members Callable paper). That is, if <font face=3D"courier new=
, monospace">cls</font> were actually a <font face=3D"courier new, monospac=
e">ns::Class*</font>, it would work, as well as a <font face=3D"courier new=
, monospace">std::reference_wrapper<ns::Class></font> and the rest of=
the invoke protocol.<br><br></div><div>This has an immediate benefit: you =
can make this type of function reference to standard library objects. <font=
face=3D"courier new, monospace">&std::string::size</font><font face=3D=
"arial, sans-serif">=C2=A0is illegal, as the standard library is allowed to=
have default arguments, but </font><font face=3D"courier new, monospace">[=
]std::string::size</font><font face=3D"arial, sans-serif"> would be legal.<=
/font></div><div><font face=3D"arial, sans-serif"><br></font></div><div><fo=
nt face=3D"arial, sans-serif">There are possible drawbacks. For one, what s=
hould the following be:</font></div><div><font face=3D"arial, sans-serif"><=
br></font></div><div><font face=3D"arial, sans-serif"><div class=3D"prettyp=
rint" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187,=
187, 187); border-style: solid; border-width: 1px; word-wrap: break-word;"=
><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">void</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> foo</span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">{}</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br><br></span><font color=3D"#000088"><span style=3D"color: #008;" =
class=3D"styled-by-prettify">int</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> main</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">{</span></font><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">auto</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> foo </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">[]{};</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> bar </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">[]</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">foo</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">}</span></div></code></div><br>Should it capture </font><font face=3D"cou=
rier new, monospace">foo</font><font face=3D"arial, sans-serif">, call the =
</font><font face=3D"courier new, monospace">foo</font><font face=3D"arial,=
sans-serif"> function, or do something else? I'd suggest that it would=
call the </font><font face=3D"courier new, monospace">foo</font><font face=
=3D"arial, sans-serif"> function, and that if the user wanted to capture it=
would be:</font></div><div><font face=3D"arial, sans-serif"><br></font></d=
iv><div><font color=3D"#000088" style=3D"font-family: monospace; background=
-color: rgb(250, 250, 250);"><span class=3D"styled-by-prettify">int</span><=
span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);">=C2=A0main=
</span><span class=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);=
">()</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);=
">=C2=A0</span><span class=3D"styled-by-prettify" style=3D"color: rgb(102, =
102, 0);">{</span></font><span class=3D"styled-by-prettify" style=3D"font-f=
amily: monospace; background-color: rgb(250, 250, 250); color: rgb(0, 0, 0)=
;"><br>=C2=A0 =C2=A0=C2=A0</span><span class=3D"styled-by-prettify" style=
=3D"font-family: monospace; background-color: rgb(250, 250, 250); color: rg=
b(0, 0, 136);">auto</span><span class=3D"styled-by-prettify" style=3D"font-=
family: monospace; background-color: rgb(250, 250, 250); color: rgb(0, 0, 0=
);">=C2=A0foo=C2=A0</span><span class=3D"styled-by-prettify" style=3D"font-=
family: monospace; background-color: rgb(250, 250, 250); color: rgb(102, 10=
2, 0);">=3D</span><span class=3D"styled-by-prettify" style=3D"font-family: =
monospace; background-color: rgb(250, 250, 250); color: rgb(0, 0, 0);">=C2=
=A0</span><span class=3D"styled-by-prettify" style=3D"font-family: monospac=
e; background-color: rgb(250, 250, 250); color: rgb(102, 102, 0);">[]{};</s=
pan><span class=3D"styled-by-prettify" style=3D"font-family: monospace; bac=
kground-color: rgb(250, 250, 250); color: rgb(0, 0, 0);"><br>=C2=A0 =C2=A0=
=C2=A0</span><span class=3D"styled-by-prettify" style=3D"font-family: monos=
pace; background-color: rgb(250, 250, 250); color: rgb(0, 0, 136);">auto</s=
pan><span class=3D"styled-by-prettify" style=3D"font-family: monospace; bac=
kground-color: rgb(250, 250, 250); color: rgb(0, 0, 0);">=C2=A0bar=C2=A0</s=
pan><span class=3D"styled-by-prettify" style=3D"font-family: monospace; bac=
kground-color: rgb(250, 250, 250); color: rgb(102, 102, 0);">=3D</span><spa=
n class=3D"styled-by-prettify" style=3D"font-family: monospace; background-=
color: rgb(250, 250, 250); color: rgb(0, 0, 0);">=C2=A0</span><span class=
=3D"styled-by-prettify" style=3D"font-family: monospace; background-color: =
rgb(250, 250, 250); color: rgb(102, 102, 0);">[foo]</span><span class=3D"st=
yled-by-prettify" style=3D"font-family: monospace; background-color: rgb(25=
0, 250, 250); color: rgb(0, 0, 0);">foo</span><span class=3D"styled-by-pret=
tify" style=3D"font-family: monospace; background-color: rgb(250, 250, 250)=
; color: rgb(102, 102, 0);">; // or [&foo]foo to capture by reference</=
span><span class=3D"styled-by-prettify" style=3D"font-family: monospace; ba=
ckground-color: rgb(250, 250, 250); color: rgb(0, 0, 0);"><br></span><span =
class=3D"styled-by-prettify" style=3D"font-family: monospace; background-co=
lor: rgb(250, 250, 250); color: rgb(102, 102, 0);">}</span><br></div><div><=
font face=3D"arial, sans-serif"><br>But that might not be feasible.</font><=
/div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/438053e9-d818-4269-855a-abb08ed3a556%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/438053e9-d818-4269-855a-abb08ed3a556=
%40isocpp.org</a>.<br />
------=_Part_1_1896248956.1500096569148--
------=_Part_0_611284157.1500096569133--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sat, 15 Jul 2017 07:41:01 -0700 (PDT)
Raw View
------=_Part_196_941082915.1500129661270
Content-Type: multipart/alternative;
boundary="----=_Part_197_1441130707.1500129661271"
------=_Part_197_1441130707.1500129661271
Content-Type: text/plain; charset="UTF-8"
On Saturday, July 15, 2017 at 1:29:29 AM UTC-4, Justin Bassett wrote:
>
> This seems to be almost the same as Suggesting a syntax for wraping
> overload set
> <https://groups.google.com/a/isocpp.org/d/msg/std-proposals/lOTFtnNRahY/yustd1j6BgAJ>
> .
>
There has already been a proposal (actually two) submitted suggesting
similar things. I don't know what happened to them, but I wish they'd move
forward. We all seem to know that we need it, but it never seems to advance.
Currently in C++, we can get a function pointer with &ns::foo or ns::foo. The
> problem with this is that, if foo is overloaded, it fails to compile as
> it actually needs to produce a pointer to a concrete function. I find this
> unintuitive. To get the behavior I would expect, one would need to write:
>
> [](auto&&... args) { return ns::foo(std::forward<decltype(args)>(args
> )...); }
>
> Or in the truly general case:
>
> [](auto&&... args) noexcept(noexcept(ns::foo(std::forward<decltype(args)>(
> args)...)))
> -> decltype(ns::foo(std::forward<decltype(args)>(args
> )...)) {
> return ns::foo(std::forward<decltype(args)>(args)...);
> }
>
> Or, using Barry's Abbreviated Lambdas
> <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0573r0.html>:
>
> [](args...) => ns::foo(>>args...)
>
> In that paper, it was mentioned that there is an idea floating around to
> make this:
>
> []ns::foo
>
> I think this should be added to C++.
>
> Furthermore, if Make Pointers to Members Callable
> <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0312r1.html> happens,
> it makes sense to have the corresponding thing for member pointers:
>
> []ns::Class::member
>
> Which would be roughly equivalent to:
>
> [](auto&& cls, auto&&... args) {
> static_assert(std::is_same_v<ns::Class, std::decay_t<decltype(cls)>>);
> return std::forward<decltype(cls)>(cls).member(std::forward<decltype(
> args)>(args)...);
> }
>
> But it would make sense to allow the cls parameter to be the same as in
> std::invoke (as in the Make Pointers to Members Callable paper). That is,
> if cls were actually a ns::Class*, it would work, as well as a
> std::reference_wrapper<ns::Class> and the rest of the invoke protocol.
>
> This has an immediate benefit: you can make this type of function
> reference to standard library objects. &std::string::size is illegal, as
> the standard library is allowed to have default arguments, but
> []std::string::size would be legal.
>
> There are possible drawbacks. For one, what should the following be:
>
> void foo() {}
>
> int main() {
> auto foo = []{};
> auto bar = []foo;
> }
>
> Should it capture foo, call the foo function, or do something else? I'd
> suggest that it would call the foo function, and that if the user wanted
> to capture it would be:
>
> int main() {
> auto foo = []{};
> auto bar = [foo]foo; // or [&foo]foo to capture by reference
> }
>
> But that might not be feasible.
>
I would go farther. Remember: the idea is that `[]name` becomes a functor
such that invoking it is exactly equivalent to `name(...)`. If `name`
refers to an object in local scope rather than a function name, then
`[]name` should be il-formed. Ambiguity can always be resolved by explicit
syntax; I'd rather we not
So if you want to capture the `foo` object and call it, then you need to
actually capture the `foo` object and call it: `[foo](...) {return
foo(...);}`. Shorthand notation can be used to expedite this, but I don't
think we need it to be as short as `[foo]foo`.
Also, we should allow class constructors to be wrapped via `[]typename`. It
should even work for non-class types.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/6d242393-14a8-4985-bc9d-bf5e66813cea%40isocpp.org.
------=_Part_197_1441130707.1500129661271
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Saturday, July 15, 2017 at 1:29:29 AM UTC-4, Justin Bas=
sett wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left=
: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><d=
iv>This seems to be almost the same as=C2=A0<a href=3D"https://groups.googl=
e.com/a/isocpp.org/d/msg/std-proposals/lOTFtnNRahY/yustd1j6BgAJ" target=3D"=
_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'https://groups.goo=
gle.com/a/isocpp.org/d/msg/std-proposals/lOTFtnNRahY/yustd1j6BgAJ';retu=
rn true;" onclick=3D"this.href=3D'https://groups.google.com/a/isocpp.or=
g/d/msg/std-proposals/lOTFtnNRahY/yustd1j6BgAJ';return true;">Suggestin=
g a syntax for wraping overload set</a>=C2=A0.</div></div></blockquote><div=
><br>There has already been a proposal (actually two) submitted suggesting =
similar things. I don't know what happened to them, but I wish they'=
;d move forward. We all seem to know that we need it, but it never seems to=
advance.<br><br></div><blockquote class=3D"gmail_quote" style=3D"margin: 0=
;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div di=
r=3D"ltr"><div></div>Currently in C++, we can get a function pointer with <=
font face=3D"courier new, monospace">&ns::foo</font><font face=3D"arial=
, sans-serif">=C2=A0or </font><font face=3D"courier new, monospace">ns::foo=
..=C2=A0</font>The problem with this is that, if <font face=3D"courier new, =
monospace">foo</font> is overloaded, it fails to compile=C2=A0as it actuall=
y needs to produce a pointer to a concrete function. I find this unintuitiv=
e. To get the behavior I would expect, one would need to write:<div><div><b=
r></div><div><div style=3D"background-color:rgb(250,250,250);border-color:r=
gb(187,187,187);border-style:solid;border-width:1px;word-wrap:break-word"><=
code><div><span style=3D"color:#660">[](</span><span style=3D"color:#008">a=
uto</span><span style=3D"color:#660">&&...</span><span style=3D"col=
or:#000"> args</span><span style=3D"color:#660">)</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#660">{</span><span style=3D"color:#00=
0"> </span><span style=3D"color:#008">return</span><span style=3D"color:#00=
0"> ns</span><span style=3D"color:#660">::</span><span style=3D"color:#000"=
>foo</span><span style=3D"color:#660">(</span><span style=3D"color:#000">st=
d</span><span style=3D"color:#660">::</span><span style=3D"color:#000">forw=
ard</span><span style=3D"color:#660"><</span><span style=3D"color:#008">=
decltype</span><span style=3D"color:#660">(</span><span style=3D"color:#000=
"><wbr>args</span><span style=3D"color:#660">)>(</span><span style=3D"co=
lor:#000">args</span><span style=3D"color:#660">)...);</span><span style=3D=
"color:#000"> </span><span style=3D"color:#660">}</span><span style=3D"colo=
r:#000"><br></span></div></code></div><br>Or in the truly general case:</di=
v><div><br></div><div><div style=3D"background-color:rgb(250,250,250);borde=
r-color:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:brea=
k-word"><code><div><font color=3D"#660066"><span style=3D"color:#660">[](</=
span><span style=3D"color:#008">auto</span><span style=3D"color:#660">&=
&...</span><span style=3D"color:#000"> args</span><span style=3D"color:=
#660">)</span><span style=3D"color:#000"> noexcept</span><span style=3D"col=
or:#660">(</span><span style=3D"color:#000">noexcept</span><span style=3D"c=
olor:#660">(</span><span style=3D"color:#000">ns</span><span style=3D"color=
:#660">::</span><span style=3D"color:#000">foo</span><span style=3D"color:#=
660">(</span><span style=3D"color:#000">std</span><span style=3D"color:#660=
">:<wbr>:</span><span style=3D"color:#000">forward</span><span style=3D"col=
or:#660"><</span><span style=3D"color:#008">decltype</span><span style=
=3D"color:#660">(</span><span style=3D"color:#000">args</span><span style=
=3D"color:#660">)>(</span><span style=3D"color:#000">args</span><span st=
yle=3D"color:#660">)<wbr>...)))</span><span style=3D"color:#000"><br>=C2=A0=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"col=
or:#660">-></span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#008">decltype</span><span style=3D"color:#660">(</span><span style=3D"co=
lor:#000">ns</span><span style=3D"color:#660">::</span><span style=3D"color=
:#000">foo</span><span style=3D"color:#660">(</span><span style=3D"color:#0=
00">std</span><span style=3D"color:#660">::</span><span style=3D"color:#000=
">forward</span><span style=3D"color:#660"><</span><span style=3D"color:=
#008"><wbr>decltype</span><span style=3D"color:#660">(</span><span style=3D=
"color:#000">args</span><span style=3D"color:#660">)>(</span><span style=
=3D"color:#000">args</span><span style=3D"color:#660">)...))</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">return<=
/span><span style=3D"color:#000"> ns</span><span style=3D"color:#660">::</s=
pan><span style=3D"color:#000">foo</span><span style=3D"color:#660">(</span=
><span style=3D"color:#000">std</span><span style=3D"color:#660">::</span><=
span style=3D"color:#000">forward</span><span style=3D"color:#660"><</sp=
an><span style=3D"color:#008">decltype</span><span style=3D"color:#660">(</=
span><span style=3D"color:#000"><wbr>args</span><span style=3D"color:#660">=
)>(</span><span style=3D"color:#000">args</span><span style=3D"color:#66=
0">)...);</span><span style=3D"color:#000"><br></span><span style=3D"color:=
#660">}</span></font></div></code></div><div><br></div>Or, using <a href=3D=
"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0573r0.html" targ=
et=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'http://www.g=
oogle.com/url?q\x3dhttp%3A%2F%2Fwww.open-std.org%2Fjtc1%2Fsc22%2Fwg21%2Fdoc=
s%2Fpapers%2F2017%2Fp0573r0.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFD=
QzjoO-cXpIgHAWXa37a13ryV7g';return true;" onclick=3D"this.href=3D'h=
ttp://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.open-std.org%2Fjtc1%2Fsc22%2=
Fwg21%2Fdocs%2Fpapers%2F2017%2Fp0573r0.html\x26sa\x3dD\x26sntz\x3d1\x26usg\=
x3dAFQjCNFDQzjoO-cXpIgHAWXa37a13ryV7g';return true;">Barry's Abbrev=
iated Lambdas</a>:</div><div><br></div><div><div style=3D"background-color:=
rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;border-wi=
dth:1px;word-wrap:break-word"><code><div><span style=3D"color:rgb(0,0,0);fo=
nt-size:medium;text-align:justify;white-space:pre"><span style=3D"color:#66=
0">[](</span><span style=3D"color:#000">args</span><span style=3D"color:#66=
0">...)</span><span style=3D"color:#000"> </span><span style=3D"color:#660"=
>=3D></span><span style=3D"color:#000"> ns</span><span style=3D"color:#6=
60">::</span><span style=3D"color:#000">foo</span><span style=3D"color:#660=
">(>></span><span style=3D"color:#000">args</span><span style=3D"colo=
r:#660">...)</span></span><span style=3D"color:#000"><br></span></div></cod=
e></div><br>In that paper, it was mentioned that there is an idea floating =
around to make this:</div><div><br></div><div><div style=3D"background-colo=
r:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;border-=
width:1px;word-wrap:break-word"><code><div><font color=3D"#660066"><span st=
yle=3D"color:#660">[]</span><span style=3D"color:#000">ns</span><span style=
=3D"color:#660">::</span><span style=3D"color:#000">foo</span></font></div>=
</code></div><br>I think this should be added to C++.</div><div><br></div><=
div>Furthermore, if <a href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/=
papers/2017/p0312r1.html" target=3D"_blank" rel=3D"nofollow" onmousedown=3D=
"this.href=3D'http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.open-std.=
org%2Fjtc1%2Fsc22%2Fwg21%2Fdocs%2Fpapers%2F2017%2Fp0312r1.html\x26sa\x3dD\x=
26sntz\x3d1\x26usg\x3dAFQjCNGKq4ARWOJv5GERNRlrOwEOZzbEgQ';return true;"=
onclick=3D"this.href=3D'http://www.google.com/url?q\x3dhttp%3A%2F%2Fww=
w.open-std.org%2Fjtc1%2Fsc22%2Fwg21%2Fdocs%2Fpapers%2F2017%2Fp0312r1.html\x=
26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGKq4ARWOJv5GERNRlrOwEOZzbEgQ';re=
turn true;">Make Pointers to Members Callable</a>=C2=A0happens, it makes se=
nse to have the corresponding thing for member pointers:</div><div><br></di=
v><div><div style=3D"background-color:rgb(250,250,250);border-color:rgb(187=
,187,187);border-style:solid;border-width:1px;word-wrap:break-word"><code><=
div><font color=3D"#660066"><span style=3D"color:#660">[]</span><span style=
=3D"color:#000">ns</span><span style=3D"color:#660">::</span><span style=3D=
"color:#606">Class</span><span style=3D"color:#660">::</span><span style=3D=
"color:#000">member</span></font></div></code></div><br>Which would be roug=
hly equivalent to:</div></div><div><br></div><div><div style=3D"background-=
color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;bor=
der-width:1px;word-wrap:break-word"><code><div><span style=3D"color:#660">[=
](</span><span style=3D"color:#008">auto</span><span style=3D"color:#660">&=
amp;&</span><span style=3D"color:#000"> cls</span><span style=3D"color:=
#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:#008"=
>auto</span><span style=3D"color:#660">&&...</span><span style=3D"c=
olor:#000"> args</span><span style=3D"color:#660">)</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#660">{</span><span style=3D"color:#=
000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">static_assert</spa=
n><span style=3D"color:#660">(</span><span style=3D"color:#000">std</span><=
span style=3D"color:#660">::</span><span style=3D"color:#000">is_same_v</sp=
an><span style=3D"color:#660"><</span><span style=3D"color:#000">n<wbr>s=
</span><span style=3D"color:#660">::</span><span style=3D"color:#606">Class=
</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> std</=
span><span style=3D"color:#660">::</span><span style=3D"color:#000">decay_t=
</span><span style=3D"color:#660"><</span><span style=3D"color:#008">dec=
ltype</span><span style=3D"color:#660">(</span><span style=3D"color:#000">c=
ls</span><span style=3D"color:#660">)>>);</span><span style=3D"color:=
#000"><br></span><font color=3D"#000000"><span style=3D"color:#000">=C2=A0 =
=C2=A0 </span><span style=3D"color:#008">return</span><span style=3D"color:=
#000"> std</span><span style=3D"color:#660">::</span><span style=3D"color:#=
000">forward</span><span style=3D"color:#660"><</span><span style=3D"col=
or:#008">decltype</span><span style=3D"color:#660">(</span><span style=3D"c=
olor:#000">cls</span><span style=3D"color:#660">)>(</span><span style=3D=
"color:#000">cl<wbr>s</span><span style=3D"color:#660">).</span><span style=
=3D"color:#000">member</span><span style=3D"color:#660">(</span><span style=
=3D"color:#000">std</span><span style=3D"color:#660">::</span><span style=
=3D"color:#000">forward</span><span style=3D"color:#660"><</span><span s=
tyle=3D"color:#008">decltyp<wbr>e</span><span style=3D"color:#660">(</span>=
<span style=3D"color:#000">args</span><span style=3D"color:#660">)>(</sp=
an><span style=3D"color:#000">args</span><span style=3D"color:#660">)...);<=
/span><span style=3D"color:#000"><br></span><span style=3D"color:#660">}</s=
pan><span style=3D"color:#000"><br></span></font></div></code></div><div><b=
r></div>But it would make sense to allow the <font face=3D"courier new, mon=
ospace">cls</font> parameter to be the same as in <font face=3D"courier new=
, monospace">std::invoke</font> (as in the Make Pointers to Members Callabl=
e paper). That is, if <font face=3D"courier new, monospace">cls</font> were=
actually a <font face=3D"courier new, monospace">ns::Class*</font>, it wou=
ld work, as well as a <font face=3D"courier new, monospace">std::reference_=
wrapper<ns::<wbr>Class></font> and the rest of the invoke protocol.<b=
r><br></div><div>This has an immediate benefit: you can make this type of f=
unction reference to standard library objects. <font face=3D"courier new, m=
onospace">&std::string::size</font><font face=3D"arial, sans-serif">=C2=
=A0is illegal, as the standard library is allowed to have default arguments=
, but </font><font face=3D"courier new, monospace">[]std::string::size</fon=
t><font face=3D"arial, sans-serif"> would be legal.</font></div><div><font =
face=3D"arial, sans-serif"><br></font></div><div><font face=3D"arial, sans-=
serif">There are possible drawbacks. For one, what should the following be:=
</font></div><div><font face=3D"arial, sans-serif"><br></font></div><div><f=
ont face=3D"arial, sans-serif"><div style=3D"background-color:rgb(250,250,2=
50);border-color:rgb(187,187,187);border-style:solid;border-width:1px;word-=
wrap:break-word"><code><div><span style=3D"color:#008">void</span><span sty=
le=3D"color:#000"> foo</span><span style=3D"color:#660">()</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#660">{}</span><span style=3D=
"color:#000"><br><br></span><font color=3D"#000088"><span style=3D"color:#0=
08">int</span><span style=3D"color:#000"> main</span><span style=3D"color:#=
660">()</span><span style=3D"color:#000"> </span><span style=3D"color:#660"=
>{</span></font><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span s=
tyle=3D"color:#008">auto</span><span style=3D"color:#000"> foo </span><span=
style=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#660">[]{};</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0=
</span><span style=3D"color:#008">auto</span><span style=3D"color:#000"> b=
ar </span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> =
</span><span style=3D"color:#660">[]</span><span style=3D"color:#000">foo</=
span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br></sp=
an><span style=3D"color:#660">}</span></div></code></div><br>Should it capt=
ure </font><font face=3D"courier new, monospace">foo</font><font face=3D"ar=
ial, sans-serif">, call the </font><font face=3D"courier new, monospace">fo=
o</font><font face=3D"arial, sans-serif"> function, or do something else? I=
'd suggest that it would call the </font><font face=3D"courier new, mon=
ospace">foo</font><font face=3D"arial, sans-serif"> function, and that if t=
he user wanted to capture it would be:</font></div><div><font face=3D"arial=
, sans-serif"><br></font></div><div><font style=3D"font-family:monospace;ba=
ckground-color:rgb(250,250,250)" color=3D"#000088"><span>int</span><span st=
yle=3D"color:rgb(0,0,0)">=C2=A0main</span><span style=3D"color:rgb(102,102,=
0)">()</span><span style=3D"color:rgb(0,0,0)">=C2=A0</span><span style=3D"c=
olor:rgb(102,102,0)">{</span></font><span style=3D"font-family:monospace;ba=
ckground-color:rgb(250,250,250);color:rgb(0,0,0)"><br>=C2=A0 =C2=A0=C2=A0</=
span><span style=3D"font-family:monospace;background-color:rgb(250,250,250)=
;color:rgb(0,0,136)">auto</span><span style=3D"font-family:monospace;backgr=
ound-color:rgb(250,250,250);color:rgb(0,0,0)">=C2=A0foo=C2=A0</span><span s=
tyle=3D"font-family:monospace;background-color:rgb(250,250,250);color:rgb(1=
02,102,0)">=3D</span><span style=3D"font-family:monospace;background-color:=
rgb(250,250,250);color:rgb(0,0,0)">=C2=A0</span><span style=3D"font-family:=
monospace;background-color:rgb(250,250,250);color:rgb(102,102,0)">[]{};</sp=
an><span style=3D"font-family:monospace;background-color:rgb(250,250,250);c=
olor:rgb(0,0,0)"><br>=C2=A0 =C2=A0=C2=A0</span><span style=3D"font-family:m=
onospace;background-color:rgb(250,250,250);color:rgb(0,0,136)">auto</span><=
span style=3D"font-family:monospace;background-color:rgb(250,250,250);color=
:rgb(0,0,0)">=C2=A0bar=C2=A0</span><span style=3D"font-family:monospace;bac=
kground-color:rgb(250,250,250);color:rgb(102,102,0)">=3D</span><span style=
=3D"font-family:monospace;background-color:rgb(250,250,250);color:rgb(0,0,0=
)">=C2=A0</span><span style=3D"font-family:monospace;background-color:rgb(2=
50,250,250);color:rgb(102,102,0)">[foo]</span><span style=3D"font-family:mo=
nospace;background-color:rgb(250,250,250);color:rgb(0,0,0)">foo</span><span=
style=3D"font-family:monospace;background-color:rgb(250,250,250);color:rgb=
(102,102,0)">; // or [&foo]foo to capture by reference</span><span styl=
e=3D"font-family:monospace;background-color:rgb(250,250,250);color:rgb(0,0,=
0)"><br></span><span style=3D"font-family:monospace;background-color:rgb(25=
0,250,250);color:rgb(102,102,0)">}</span><br></div><div><font face=3D"arial=
, sans-serif"><br>But that might not be feasible.</font></div></div></block=
quote><div><br>I would go farther. Remember: the idea is that `[]name` beco=
mes a functor such that invoking it is exactly equivalent to `name(...)`. I=
f `name` refers to an object in local scope rather than a function name, th=
en `[]name` should be il-formed. Ambiguity can always be resolved by explic=
it syntax; I'd rather we not <br><br>So if you want to capture the `foo=
` object and call it, then you need to actually capture the `foo` object an=
d call it: `[foo](...) {return foo(...);}`. Shorthand notation can be used =
to expedite this, but I don't think we need it to be as short as `[foo]=
foo`.<br><br>Also, we should allow class constructors to be wrapped via `[]=
typename`. It should even work for non-class types.<br></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/6d242393-14a8-4985-bc9d-bf5e66813cea%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/6d242393-14a8-4985-bc9d-bf5e66813cea=
%40isocpp.org</a>.<br />
------=_Part_197_1441130707.1500129661271--
------=_Part_196_941082915.1500129661270--
.