Topic: call_with tuple
Author: stackmachine@hotmail.com
Date: Thu, 22 Nov 2012 23:00:14 -0800 (PST)
Raw View
------=_Part_460_17664263.1353654014985
Content-Type: text/plain; charset=ISO-8859-1
Hi there,
Sometime it is necessary to call a function with a tuple by expanding the
tuple elements into the argument list. While this is fairly easy to
implement if you have sufficient knowledge of templates and template meta
programming, most people cannot do it.
template <typename Callable, typename Tuple>
auto call_with(Callable&& callable, Tuple&& tuple)
-> decltype(...)
{
return ...
}
I think you get the idea.
--
------=_Part_460_17664263.1353654014985
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Hi there,<div><br></div><div>Sometime it is necessary to call a function wi=
th a tuple by expanding the tuple elements into the argument list. While th=
is is fairly easy to implement if you have sufficient knowledge of template=
s and template meta programming, most people cannot do it.</div><div><div s=
tyle=3D"background-color: rgb(250, 250, 250); border: 1px solid rgb(187, 18=
7, 187); word-wrap: break-word;" class=3D"prettyprint"><code class=3D"prett=
yprint"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D=
"styled-by-prettify">template</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-=
prettify"><</span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">typename</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Callabl=
e</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">typename</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #606;" class=3D"styled-by-prettify">Tuple</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">></span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">auto</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> call_with</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">(</span><span style=3D"color: #606;" class=3D"styled-by-pret=
tify">Callable</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">&&</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> callable</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #606;" class=3D"styled-by-prettify">Tuple</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">&&</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> tuple</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br></span><font color=3D"#000000=
"><span style=3D"color: #000;" class=3D"styled-by-prettify"> &=
nbsp; </span></font><span style=3D"color: #660;" class=3D"styled-by-=
prettify">-></span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">decl=
type</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</spa=
n><font color=3D"#000000"><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">...</span></font><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br> &nbs=
p; </span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">return</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">...</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"co=
lor: rgb(0, 0, 0);"></span></div></code></div><br>I think you get the idea.=
</div>
<p></p>
-- <br />
<br />
<br />
<br />
------=_Part_460_17664263.1353654014985--
.
Author: =?UTF-8?Q?Andrzej_Krzemie=C5=84ski?= <akrzemi1@gmail.com>
Date: Fri, 23 Nov 2012 04:36:26 -0800 (PST)
Raw View
------=_Part_227_33382745.1353674186620
Content-Type: text/plain; charset=ISO-8859-2
Content-Transfer-Encoding: quoted-printable
W dniu pi=B1tek, 23 listopada 2012 08:00:15 UTC+1 u=BFytkownik=20
stackm...@hotmail.com napisa=B3:
>
> Hi there,
>
> Sometime it is necessary to call a function with a tuple by expanding the=
=20
> tuple elements into the argument list. While this is fairly easy to=20
> implement if you have sufficient knowledge of templates and template meta=
=20
> programming, most people cannot do it.
> template <typename Callable, typename Tuple>
> auto call_with(Callable&& callable, Tuple&& tuple)
> -> decltype(...)
> {
> return ...
> }
>
> I think you get the idea.
>
Tomasz Kaminski has proposed operator... in this group:=20
https://groups.google.com/a/isocpp.org/d/topic/std-proposals/g1HziHt1lbo/di=
scussion=20
If it was to be added, function call_with would not be necessary. You would=
=20
just type:
return callable(tuple...);
--=20
------=_Part_227_33382745.1353674186620
Content-Type: text/html; charset=ISO-8859-2
Content-Transfer-Encoding: quoted-printable
<br><br>W dniu pi=B1tek, 23 listopada 2012 08:00:15 UTC+1 u=BFytkownik stac=
km...@hotmail.com napisa=B3:<blockquote class=3D"gmail_quote" style=3D"marg=
in: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">Hi=
there,<div><br></div><div>Sometime it is necessary to call a function with=
a tuple by expanding the tuple elements into the argument list. While this=
is fairly easy to implement if you have sufficient knowledge of templates =
and template meta programming, most people cannot do it.</div><div><div sty=
le=3D"background-color:rgb(250,250,250);border:1px solid rgb(187,187,187);w=
ord-wrap:break-word"><code><div><span style=3D"color:#008">template</span><=
span style=3D"color:#000"> </span><span style=3D"color:#660"><</span><sp=
an style=3D"color:#008">typename</span><span style=3D"color:#000"> </span><=
span style=3D"color:#606">Callable</span><span style=3D"color:#660">,</span=
><span style=3D"color:#000"> </span><span style=3D"color:#008">typename</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#606">Tuple</spa=
n><span style=3D"color:#660">></span><span style=3D"color:#000"><br></sp=
an><span style=3D"color:#008">auto</span><span style=3D"color:#000"> call_w=
ith</span><span style=3D"color:#660">(</span><span style=3D"color:#606">Cal=
lable</span><span style=3D"color:#660">&&</span><span style=3D"colo=
r:#000"> callable</span><span style=3D"color:#660">,</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#606">Tuple</span><span style=3D"co=
lor:#660">&&</span><span style=3D"color:#000"> tuple</span><span st=
yle=3D"color:#660">)</span><span style=3D"color:#000"><br></span><font colo=
r=3D"#000000"><span style=3D"color:#000"> </span=
></font><span style=3D"color:#660">-></span><span style=3D"color:#000"> =
</span><span style=3D"color:#008">decltype</span><span style=3D"color:#660"=
>(</span><font color=3D"#000000"><span style=3D"color:#660">...</span></fon=
t><span style=3D"color:#660">)</span><span style=3D"color:#000"><br></span>=
<span style=3D"color:#660">{</span><span style=3D"color:#000"><br> &n=
bsp; </span><span style=3D"color:#008">return</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#660">...</span><span style=
=3D"color:#000"><br></span><span style=3D"color:#660">}</span><span style=
=3D"color:#000"><br></span><span style=3D"color:rgb(0,0,0)"></span></div></=
code></div><br>I think you get the idea.</div></blockquote><div><br>Tomasz =
Kaminski has proposed operator... in this group: <br><a href=3D"https://gro=
ups.google.com/a/isocpp.org/d/topic/std-proposals/g1HziHt1lbo/discussion">h=
ttps://groups.google.com/a/isocpp.org/d/topic/std-proposals/g1HziHt1lbo/dis=
cussion </a><br><br>If it was to be added, function call_with would not be =
necessary. You would just type:<br><div class=3D"prettyprint" style=3D"back=
ground-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-=
style: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"pre=
ttyprint"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=
=3D"styled-by-prettify">return</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> callable</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">tuple</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">...);</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br></span></div></code></div><br><br></div>
<p></p>
-- <br />
<br />
<br />
<br />
------=_Part_227_33382745.1353674186620--
.
Author: stackmachine@hotmail.com
Date: Fri, 23 Nov 2012 09:47:20 -0800 (PST)
Raw View
------=_Part_421_15597604.1353692840854
Content-Type: text/plain; charset=ISO-8859-1
Alrighty, sounds awesome!
--
------=_Part_421_15597604.1353692840854
Content-Type: text/html; charset=ISO-8859-1
Alrighty, sounds awesome!
<p></p>
-- <br />
<br />
<br />
<br />
------=_Part_421_15597604.1353692840854--
.