Topic: Make Variadic Template Args can be restricted
Author: wei zhang <lala.willzhang@gmail.com>
Date: Tue, 1 Aug 2017 23:09:55 -0700 (PDT)
Raw View
------=_Part_5745_1223559077.1501654195233
Content-Type: multipart/alternative;
boundary="----=_Part_5746_647423542.1501654195235"
------=_Part_5746_647423542.1501654195235
Content-Type: text/plain; charset="UTF-8"
c++ 1x has supported Variadic Template Args, like
template<typename ... Types> void aFunc(Types ... types){}
that let the args be any compositions of any Types. But however, sometime
we are not hoping the args are anything, we may hope that the Types should
follow some rules. In that case, template's deducing will help to report
compile error when your Args are wrong like cannot deducing to a function
according to the arguments.
Now I want an aggressive approach to achieve same purpose. In my case, I
hope the compiler can already know the correct signature of Variadic
Template Types before performing actual deducing. Here's my motivation.
## Motivation
template<class R, typename ... Args> managed_ptr<R> managed_new( Args ..
args)
{
R * ptr = new R(args...);
// Here I could record this ptr in my
managed_ptr<ret> ret = make_manmaged_ptr<R>(ptr)
return ret;
}
class ABC{
public:
ABC(int, int);
ABC(double, double, double);
};
auto ptr1=managed_new<ABC>(1, 2); //ok
auto ptr2=managed_new<ABC>(1.0); // fail compile, report error at line "R
* ptr = new R(args...);"
Compiler will report error at the line calling the new R(args...) when
compiling the last line. It might be easy to figure out what's wrong but
it wouldn't be so easy if the situation were complicated.
## How to improve
Now I think is it possible to let compiler know there's an error just when
it compiles the last line. Let's do something at template variadic args ...
template<class R, typename [R::R](...) Args > managed_ptr<R> managed_new(
Args .. args)
With this syntax, I hope the compiler could know the Args should be one of
the signature of R::R(...)
And also you may add return type in this signature.
In following case ,tempfunc is using signature of double (ABC*, const
char*, int) and int x will be converted from double
class ABC{
public:
void func();
int func(double);
double func(const char *, int);
int func(const char *, int, double);
};
template<class T, typename R [T::func](...) Args > // This sample defines 3
Template Args, T, R and Args which Args is variadic
R tempfunc(T * ptr, Args .. args)
{
return ptr->func( args... );
}
ABC * abc = new ABC()
int x = tempfunc(abc, "ABC", 1.0);
You may extract beginning parameters with definite type name
template<class T, typename R [T::func](FirstParam, ...) Args > // This
sample defines 4 Template Args, T, R,FirstParam and Args. Args is variadic
that don't have the first parameter type.
// As we defined FirstParam as Typename, the func will ignore the functions
without parameters.
R tempfunc2(T*ptr, Args .. args)
{
FirstParam myFirst;
return ptr->func(myFirst, args... );
}
You may restrict arg type by predefining it.
template<class T, typename R [T::func](type=const char *, ...) Args >
// This sample defines 3 Template Args, T,R and Args. Args is variadic
that don't have the first parameter type
// As we restrict the first parameter type, the func will only accept
functions with first parameter is const char *
You may also restrict the return type, by write return type in []
template<class T, typename R [int T::func](type=const char *, ...) Args >
// This sample defines 3 Template Args, T,R and Args. Args is variadic
that don't have the first parameter type
// As we restrict the first parameter type, the func will only accept
functions with first parameter is const char * and return type is int
// Also, the type of R must be int now. You may omit define R in this case
because it's always int.
You should write [static T::func] if you are referring a static function.
[T::func const](...) refers to a function with "const" decorate. It will
be samme if T is a typename of const class.
let T=ABC, CT=const ABC
[CT:func](...) will be same as [T::func const]
[const_cast<CT>::func ](...) is required if you are actually try to refer
ABC::func instead of ABC::func const
[virtual T::func](...) refers only virtual functions
--
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/e52a7a64-c1fd-4e1e-af55-f58da55b9f8c%40isocpp.org.
------=_Part_5746_647423542.1501654195235
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">c++ 1x has supported Variadic Template Args, like=C2=A0<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=
"><span style=3D"color: #008;" class=3D"styled-by-prettify">template</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">typename</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">...</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" clas=
s=3D"styled-by-prettify">Types</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: #008;" class=3D"styled-by-prett=
ify">void</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
aFunc</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</sp=
an><span style=3D"color: #606;" class=3D"styled-by-prettify">Types</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">...</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> types</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">){}</span></div></code></div>that let t=
he args be any compositions of any Types. =C2=A0But however, sometime we ar=
e not hoping the args are anything, we may hope that the Types should follo=
w some rules. =C2=A0In that case, template's deducing will help to repo=
rt compile error when your Args are wrong like cannot deducing to a functio=
n according to the arguments.<div>Now I want an aggressive approach to achi=
eve same purpose. =C2=A0In my case, I hope the compiler can already know th=
e correct signature of Variadic Template Types before performing actual ded=
ucing. =C2=A0Here's my motivation.</div><div><br></div><div>## Motivati=
on</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"sub=
prettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">temp=
late</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><</=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">class</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> R</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=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: #660;" class=3D=
"styled-by-prettify">...</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prett=
ify">Args</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> manage=
d_ptr</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify">R</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">></span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> managed_new</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #60=
6;" class=3D"styled-by-prettify">Args</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"st=
yled-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"><br>=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> =C2=A0<br>=C2=A0 R=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">*</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> ptr </span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">new</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> R</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">args</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">...);</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br>=C2=A0 </span><span style=3D"color: #800;" class=3D"styled-by-prett=
ify">// Here I could record this ptr in my </span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br>=C2=A0 managed_ptr</span><span style=
=3D"color: #080;" class=3D"styled-by-prettify"><ret></span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> ret </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> make_manmaged_ptr</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">R</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">>(</span><font color=3D"#000000"><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">ptr</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">)</span></font><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </span><span style=3D"col=
or: #008;" class=3D"styled-by-prettify">return</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> ret</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"style=
d-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">class</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
ABC</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: #008;" class=3D"styled-by-prettify">public</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br>=C2=A0 ABC</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">int</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">int</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
=C2=A0 ABC</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">double</s=
pan><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: #008;" class=3D"styled-by-prettify">double</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">double</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r><br><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
auto</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> ptr1<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify">managed_new</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify">ABC</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">>(</span><span style=3D"c=
olor: #066;" class=3D"styled-by-prettify">1</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"style=
d-by-prettify">2</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #800;" class=3D"styled-by-prettify">//ok</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> ptr2</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify">managed_new</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify">ABC</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">>(</span><span style=3D"color: #066;" class=
=3D"styled-by-prettify">1.0</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> =C2=A0</span><span style=3D"color: #800;" class=3D"styled-by-pret=
tify">// fail compile, report error at line "R * ptr =3D new R(args...=
);"</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r></span></div></code></div><div><br>Compiler will report error at the line=
calling the new R(args...) when compiling the last line. =C2=A0It might be=
easy to figure out what's wrong but it wouldn't be so easy if the =
situation were complicated.</div><div><br></div><div>## How to improve</div=
><div>Now I think is it possible to let compiler know there's an error =
just when it compiles the last line. =C2=A0Let's do something at templa=
te variadic args ...</div><div><br></div><div><div class=3D"prettyprint" st=
yle=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 18=
7); border-style: solid; border-width: 1px; word-wrap: break-word;"><code c=
lass=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">template</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify"><</span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">class</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> R</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">typen=
ame</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">[</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">R</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">R</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: #606;" class=3D"styled-by=
-prettify">Args</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> =C2=A0</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">></span><span style=3D"color: #000;" class=3D"styled-by-prettify"> man=
aged_ptr</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&l=
t;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">R</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">></span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> managed_new</span><spa=
n 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=
: #606;" class=3D"styled-by-prettify">Args</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"styl=
ed-by-prettify"> args</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">)</span></div></code></div><span class=3D"styled-by-prettify" st=
yle=3D"font-family: monospace; background-color: rgb(250, 250, 250); color:=
rgb(102, 102, 0);"><br></span></div><div><span class=3D"styled-by-prettify=
" style=3D"font-family: monospace; background-color: rgb(250, 250, 250); co=
lor: rgb(0, 0, 0);">With this syntax, I hope the compiler could know the Ar=
gs should be one of the signature of R::R(...)</span></div><div><span class=
=3D"styled-by-prettify" style=3D"font-family: monospace; background-color: =
rgb(250, 250, 250); color: rgb(0, 0, 0);">And also you may add return type =
in this signature.</span></div><div><span class=3D"styled-by-prettify" styl=
e=3D"font-family: monospace; background-color: rgb(250, 250, 250); color: r=
gb(0, 0, 0);"><br></span></div><div><span class=3D"styled-by-prettify" styl=
e=3D"font-family: monospace; background-color: rgb(250, 250, 250); color: r=
gb(0, 0, 0);"><br></span></div><div><span class=3D"styled-by-prettify" styl=
e=3D"font-family: monospace; background-color: rgb(250, 250, 250); color: r=
gb(0, 0, 0);"><br></span></div><div><span class=3D"styled-by-prettify" styl=
e=3D"font-family: monospace; background-color: rgb(250, 250, 250); color: r=
gb(0, 0, 0);"><span class=3D"styled-by-prettify">In following case ,tempfun=
c is using signature of double (ABC*, const char*, int)=C2=A0</span>and int=
x will be converted from double<br></span></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;"><cod=
e class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color:=
#008;" class=3D"styled-by-prettify">class</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> ABC</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">public</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r>=C2=A0 =C2=A0</span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">void</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
func</span><span style=3D"color: #660;" class=3D"styled-by-prettify">();</s=
pan><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-prettify">int<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> func</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">double</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0</span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">double</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> func</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">char</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </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: #008;" class=3D"styled-by-prettify">int</span><span s=
tyle=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><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> func</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">char</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </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: #008;" class=3D"styled-by-prettify">int</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">double</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"style=
d-by-prettify">};</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>template</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
lt;</span><span style=3D"color: #008;" class=3D"styled-by-prettify">class</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> T</span><sp=
an 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=
: #008;" class=3D"styled-by-prettify">typename</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> R </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">[</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify">T</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">func</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: #606;" class=3D"styled-by-prettify">Args</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"> </span><span style=3D"color: rgb(136=
, 0, 0);"><span style=3D"color: #800;" class=3D"styled-by-prettify">// This=
sample defines 3 Template Args, T, R and Args which Args is variadic</span=
></span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>R tem=
pfunc</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">T </span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">*</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> ptr</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: #606;" class=3D"=
styled-by-prettify">Args</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">..</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> ar=
gs</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><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </span><span style=3D=
"color: #008;" class=3D"styled-by-prettify">return</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> ptr</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">-></span><span style=3D"color: #000;" =
class=3D"styled-by-prettify">func</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> args</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">...</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">);</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>ABC </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">*</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> abc </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">new</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> ABC</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">()</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">int</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> x </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> tempfunc</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">abc</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #080;" class=3D"styled-by-p=
rettify">"ABC"</span><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: #066;" class=3D"styled-by-prettify">1.0<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> =C2=A0</span></div=
></code></div><div><span class=3D"styled-by-prettify" style=3D"font-family:=
monospace; background-color: rgb(250, 250, 250); color: rgb(0, 0, 0);"><br=
></span></div><div><span class=3D"styled-by-prettify" style=3D"font-family:=
monospace; background-color: rgb(250, 250, 250); color: rgb(0, 0, 0);">You=
may extract beginning parameters with definite type name</span></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-wr=
ap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint">=
<span style=3D"color: #008;" class=3D"styled-by-prettify">template</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">class</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> T</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">typename</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> R </span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">[</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">func</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">](</span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">FirstParam</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"styled-by-prettify">...)</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">Args</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
></span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #800;" class=3D"styled-by-prettify">// This sample =
defines 4 Template Args, T, R,FirstParam and Args. =C2=A0Args is variadic t=
hat don't have the first parameter type. </span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #800;" =
class=3D"styled-by-prettify">// As we defined FirstParam as Typename, the f=
unc will ignore the functions without parameters.</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br>R tempfunc2</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify">T</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">*</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify">ptr</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: #606;" class=3D"styled-by-prettify">Args</sp=
an><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"> args</span><span style=3D"colo=
r: #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><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">FirstParam</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> myFirst</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">return</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> ptr</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">-></span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">func</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">myFirs=
t</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><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><span style=3D"color: #660;" class=
=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br></span></div></code></div><div><br><span style=3D"backgr=
ound-color: rgb(250, 250, 250); color: rgb(0, 0, 0); font-family: monospace=
;">You may restrict arg type by predefining it.</span></div><div class=3D"p=
rettyprint" style=3D"background-color: rgb(250, 250, 250); border-color: rg=
b(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: break-=
word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">template</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">class</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> T</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">typename</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> R </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>[</span><span style=3D"color: #000;" class=3D"styled-by-prettify">T</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">func</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">](</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify">type</span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">=3D</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">char</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">*,</s=
pan><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"> </span><span style=3D"color=
: #606;" class=3D"styled-by-prettify">Args</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"st=
yled-by-prettify"> <br></span><span style=3D"color: #800;" class=3D"styled-=
by-prettify">// This sample defines 3 Template Args, T,R and Args. =C2=A0Ar=
gs is variadic that don't have the first parameter type</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"=
color: #800;" class=3D"styled-by-prettify">// As we restrict the first para=
meter type, the func will only accept functions with first parameter is con=
st char *</span></div></code></div><div><font color=3D"#000000" face=3D"mon=
ospace"><span style=3D"background-color: rgb(250, 250, 250);"><br></span></=
font></div><div><font color=3D"#000000" face=3D"monospace"><span style=3D"b=
ackground-color: rgb(250, 250, 250);">You may also restrict the return type=
, by write return type in []</span></font></div><div><div class=3D"prettypr=
int" 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"co=
lor: #008;" class=3D"styled-by-prettify">template</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">class</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> T</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: #008;" class=3D"styled-by-prettify=
">typename</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
R </span><span style=3D"color: #660;" class=3D"styled-by-prettify">[</span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> T</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify">func</span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">](</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">type</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">=3D</span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">const</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">cha=
r</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">*,</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">...)</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" clas=
s=3D"styled-by-prettify">Args</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: #000;" class=3D"styled-by-pretti=
fy"> <br></span><span style=3D"color: #800;" class=3D"styled-by-prettify">/=
/ This sample defines 3 Template Args, T,R and Args. =C2=A0Args is variadic=
that don't have the first parameter type</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #800;" =
class=3D"styled-by-prettify">// As we restrict the first parameter type, th=
e func will only accept functions with first parameter is const char * and =
return type is int</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br></span><span style=3D"color: #800;" class=3D"styled-by-prettify=
">// Also, the type of R must be int now. =C2=A0You may omit define R in th=
is case because it's always int.</span></div></code></div></div><div><s=
pan style=3D"background-color: rgb(250, 250, 250); color: rgb(0, 0, 0); fon=
t-family: monospace;"><br></span></div><div><br></div><div><span class=3D"s=
tyled-by-prettify" style=3D""><div style=3D"color: rgb(34, 34, 34); font-fa=
mily: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">=
<span class=3D"styled-by-prettify" style=3D"font-family: monospace; backgro=
und-color: rgb(250, 250, 250); color: rgb(0, 0, 0);">You should write [stat=
ic T::func] if you are referring a static function.</span></div><div style=
=3D"color: rgb(34, 34, 34); font-family: Arial, Helvetica, sans-serif; back=
ground-color: rgb(255, 255, 255);"><span class=3D"styled-by-prettify" style=
=3D"font-family: monospace; background-color: rgb(250, 250, 250); color: rg=
b(0, 0, 0);">[T::func=C2=A0</span><span style=3D"background-color: rgb(250,=
250, 250); color: rgb(0, 0, 0); font-family: monospace;">const</span><span=
style=3D"background-color: rgb(250, 250, 250); color: rgb(0, 0, 0); font-f=
amily: monospace;">](...) =C2=A0refers to a function with "const"=
decorate. =C2=A0It will be samme if T is a typename of const class.</span>=
</div><div style=3D"color: rgb(34, 34, 34); font-family: Arial, Helvetica, =
sans-serif; background-color: rgb(255, 255, 255);"><span style=3D"backgroun=
d-color: rgb(250, 250, 250); color: rgb(0, 0, 0); font-family: monospace;">=
let T=3DABC, CT=3Dconst ABC</span></div><div style=3D"color: rgb(34, 34, 34=
); font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 25=
5, 255);"><span style=3D"background-color: rgb(250, 250, 250); color: rgb(0=
, 0, 0); font-family: monospace;">[CT:func](...) will be same as [T::func c=
onst]</span></div><div style=3D"color: rgb(34, 34, 34); font-family: Arial,=
Helvetica, sans-serif; background-color: rgb(255, 255, 255);"><span style=
=3D"background-color: rgb(250, 250, 250); color: rgb(0, 0, 0); font-family:=
monospace;">[const_cast<CT>::func ](...) is required if you are actu=
ally try to refer ABC::func instead of ABC::func const</span></div><div sty=
le=3D""><font color=3D"#000000" face=3D"monospace"><span style=3D"backgroun=
d-color: rgb(250, 250, 250);">[virtual T::func](...) refers only virtual fu=
nctions</span></font></div><div style=3D"color: rgb(34, 34, 34); font-famil=
y: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"><sp=
an style=3D"background-color: rgb(250, 250, 250); color: rgb(0, 0, 0); font=
-family: monospace;"><br></span></div><div style=3D"color: rgb(34, 34, 34);=
font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255,=
255);"><span style=3D"background-color: rgb(250, 250, 250); color: rgb(0, =
0, 0); font-family: monospace;"><br></span></div></span></div><div><span cl=
ass=3D"styled-by-prettify" style=3D"font-family: monospace; background-colo=
r: rgb(250, 250, 250); color: rgb(0, 0, 0);"><br></span></div><div><span cl=
ass=3D"styled-by-prettify" style=3D"font-family: monospace; background-colo=
r: rgb(250, 250, 250); color: rgb(0, 0, 0);"><br></span></div><div><span cl=
ass=3D"styled-by-prettify" style=3D"font-family: monospace; background-colo=
r: rgb(250, 250, 250); color: rgb(0, 0, 0);"><br></span></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/e52a7a64-c1fd-4e1e-af55-f58da55b9f8c%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/e52a7a64-c1fd-4e1e-af55-f58da55b9f8c=
%40isocpp.org</a>.<br />
------=_Part_5746_647423542.1501654195235--
------=_Part_5745_1223559077.1501654195233--
.
Author: Magnus Fromreide <magfr@lysator.liu.se>
Date: Wed, 2 Aug 2017 10:05:07 +0200
Raw View
On Tue, Aug 01, 2017 at 11:09:55PM -0700, wei zhang wrote:
> c++ 1x has supported Variadic Template Args, like
> template<typename ... Types> void aFunc(Types ... types){}
> that let the args be any compositions of any Types. But however, sometime
> we are not hoping the args are anything, we may hope that the Types should
> follow some rules. In that case, template's deducing will help to report
> compile error when your Args are wrong like cannot deducing to a function
> according to the arguments.
> Now I want an aggressive approach to achieve same purpose. In my case, I
> hope the compiler can already know the correct signature of Variadic
> Template Types before performing actual deducing.
Could you please look at the concepts proposal and see if it is expressive
enough for you.
/MF
--
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/20170802080507.GA6487%40noemi.bahnhof.se.
.
Author: Bengt Gustafsson <bengt.gustafsson@beamways.com>
Date: Wed, 2 Aug 2017 15:15:19 -0700 (PDT)
Raw View
------=_Part_6499_740607843.1501712119858
Content-Type: multipart/alternative;
boundary="----=_Part_6500_20211123.1501712119858"
------=_Part_6500_20211123.1501712119858
Content-Type: text/plain; charset="UTF-8"
I think that this use case would be covered by concepts. However, I have
been constantly coming back to the similar issue of not being able to
restrict function parameters to any number of a certain type. What you want
to write is something like:
template<???> double add_all(double... terms);
The problem is what to write in the <> clause as the only thing that's
actually templated is the number of terms at this call site. The reasons
for wanting this include:
1. It is something you quite often want to do, and now you get the error
message "further in" than required, just as in the OP case.
2. All arguments are coerced to be double rather than their separate types
inside the function, so that casting can be avoided (weak reson).
3. Overload resolution will work differently than for an unqualified
template<T...> version which "eats everything". My supposition is that for
each call site with n actual arguments a version of the function with that
many doubles will be in the overload set to consider.
A generalized case would be:
template<typename T> void fun(T... ts);
Which looks like it could work today, but doesn't. I think this could be
specified to work with a new rule, (there is a value pack but no type
pack), but this still doesn't solve the specific-type case. The problem
with allowing this would be what T should be if the actual parameter types
are different. This should be the same as std::common_type<Ts...>. This
makes it quite easy to get an ambiguity when working with numeric
expressions, but there seems to be no other reasonable answer.
As above, the sane question would be whether this can be expressed easily
using concepts. I don't think so. The problem is that whatever requires
clause you put on the function you would still get a template function with
the original types forwarded into its body:
template<typename... Ts> double add_all(Ts... ts) requires
(is_constructible<double, Ts> ... &&);
Well, I'm not sure about the fold expression syntax at this time of day,
but something like that. Anyway: It is obvious that for the function body
there is a large difference between getting a number of doubles or a number
of stuff convertible to doubles. Note that this also increases the number
of template instantiations needed during compilation.
Issues remaining:
1. Is this worthwhile pursuing? I thinks so, at least from my experience
you often start out thinking "this function should take any number of
doubles" only to later realize there is no syntax for this and you have to
let the function take "anything".
2. If yes, can a suitable syntax be found?
--
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/4c43dcb0-d7d8-4c4a-b320-56f2fce63a6b%40isocpp.org.
------=_Part_6500_20211123.1501712119858
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I think that this use case would be covered by concepts. H=
owever, I have been constantly coming back to the similar issue of not bein=
g able to restrict function parameters to any number of a certain type. Wha=
t you want to write is something like:<div><br></div><div>template<???&g=
t; double add_all(double... terms);</div><div><br></div><div>The problem is=
what to write in the <> clause as the only thing that's actually=
templated is the number of terms at this call site. The reasons for wantin=
g this include:</div><div><br></div><div>1. It is something you quite often=
want to do, and now you get the error message "further in" than =
required, just as in the OP case.</div><div><br></div><div>2. All arguments=
are coerced to be double rather than their separate types inside the funct=
ion, so that casting can be avoided (weak reson).</div><div><br></div><div>=
3. Overload resolution will work differently than for an unqualified templa=
te<T...> version which "eats everything". My supposition is=
that for each call site with n actual arguments a version of the function =
with that many doubles will be in the overload set to consider.</div><div><=
br></div><div>A generalized case would be:</div><div><br></div><div>templat=
e<typename T> void fun(T... ts);<br></div><div><br></div><div>Which l=
ooks like it could work today, but doesn't. I think this could be speci=
fied to work with a new rule, (there is a value pack but no type pack), but=
this still doesn't solve the specific-type case. The problem with allo=
wing this would be what T should be if the actual parameter types are diffe=
rent. This should be the same as std::common_type<Ts...>. This makes =
it quite easy to get an ambiguity when working with numeric expressions, bu=
t there seems to be no other reasonable answer.</div><div><br></div><div>As=
above, the sane question would be whether this can be expressed easily usi=
ng concepts. I don't think so. The problem is that whatever requires cl=
ause you put on the function you would still get a template function with t=
he original types forwarded into its body:</div><div><br></div><div>templat=
e<typename... Ts> double add_all(Ts... ts) requires (is_constructible=
<double, Ts> ... &&);</div><div><br></div><div>Well, I'm =
not sure about the fold expression syntax at this time of day, but somethin=
g like that. Anyway: It is obvious that for the function body there is a la=
rge difference between getting a number of doubles or a number of stuff con=
vertible to doubles. Note that this also increases the number of template i=
nstantiations needed during compilation.</div><div><br></div><div>Issues re=
maining:</div><div><br></div><div>1. Is this worthwhile pursuing? I thinks =
so, at least from my experience you often start out thinking "this fun=
ction should take any number of doubles" only to later realize there i=
s no syntax for this and you have to let the function take "anything&q=
uot;.</div><div><br></div><div>2. If yes, can a suitable syntax be found?</=
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/4c43dcb0-d7d8-4c4a-b320-56f2fce63a6b%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/4c43dcb0-d7d8-4c4a-b320-56f2fce63a6b=
%40isocpp.org</a>.<br />
------=_Part_6500_20211123.1501712119858--
------=_Part_6499_740607843.1501712119858--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Thu, 3 Aug 2017 01:35:36 +0300
Raw View
On 3 August 2017 at 01:15, Bengt Gustafsson
<bengt.gustafsson@beamways.com> wrote:
> 1. Is this worthwhile pursuing? I thinks so, at least from my experience you
> often start out thinking "this function should take any number of doubles"
> only to later realize there is no syntax for this and you have to let the
> function take "anything".
So constraining the parameters in the pack to all be the same as
double doesn't work for you? Yes, I know it's
slightly different - the parameters cannot be of different types,
because that's how the deduction rules
work.
An alternative approach is of course using a variadic tuple of double,
or an initializer list. The latter doesn't
require the function to be a template. The former requires that the
first thing you do in your function is
to convert the argument tuple into a tuple<doubles go here>, and if
you need to constrain the function,
you need to do a bit more metaprogramming to check that a
tuple<pack...> is convertible to a tuple<double...>.
And the downside of both of these approaches is having to put braces
around call arguments.
--
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/CAFk2RUagQb40sdtB0OqjFsTL_VuALhki%2BJqL%3D1WTu7dB6dkv1g%40mail.gmail.com.
.
Author: wei zhang <lala.willzhang@gmail.com>
Date: Thu, 3 Aug 2017 00:50:00 -0700 (PDT)
Raw View
------=_Part_6726_458666372.1501746600832
Content-Type: multipart/alternative;
boundary="----=_Part_6727_642357973.1501746600832"
------=_Part_6727_642357973.1501746600832
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
I'm wondering how to write above manage_new<>() with Concept.
template<T, typename ... Args> requires (Args .. args){ new T(args ...); }
managed_ptr<T> manage_new(Args ... args) =20
{ =20
}
I think that's acceptable in this case. =20
But is it possible for an IDE prompting a param list when I typing ,=20
according to concept definition?
managed_new<ABC>(=20
I hope the IDE will prompt you with
(int, int)
(double, double, double)
in this case?
=E5=9C=A8 2017=E5=B9=B48=E6=9C=882=E6=97=A5=E6=98=9F=E6=9C=9F=E4=B8=89 UTC+=
8=E4=B8=8B=E5=8D=884:05:12=EF=BC=8CMagnus Fromreide=E5=86=99=E9=81=93=EF=BC=
=9A
>
> On Tue, Aug 01, 2017 at 11:09:55PM -0700, wei zhang wrote:=20
> > c++ 1x has supported Variadic Template Args, like=20
> > template<typename ... Types> void aFunc(Types ... types){}=20
> > that let the args be any compositions of any Types. But however,=20
> sometime=20
> > we are not hoping the args are anything, we may hope that the Types=20
> should=20
> > follow some rules. In that case, template's deducing will help to=20
> report=20
> > compile error when your Args are wrong like cannot deducing to a=20
> function=20
> > according to the arguments.=20
> > Now I want an aggressive approach to achieve same purpose. In my case,=
=20
> I=20
> > hope the compiler can already know the correct signature of Variadic=20
> > Template Types before performing actual deducing.=20
>
> Could you please look at the concepts proposal and see if it is expressiv=
e=20
> enough for you.=20
>
> /MF=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/61698e62-6686-4153-8c72-d38592c41630%40isocpp.or=
g.
------=_Part_6727_642357973.1501746600832
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I'm wondering how to write above manage_new<>() =
with Concept.<div class=3D"prettyprint" style=3D"background-color: rgb(250,=
250, 250); border-color: rgb(187, 187, 187); border-style: solid; border-w=
idth: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div class=
=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">template</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
><</span><span style=3D"color: #000;" class=3D"styled-by-prettify">T</sp=
an><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: #008;" class=3D"styled-by-prettify">typename</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;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styl=
ed-by-prettify">Args</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">></span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> requires </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">(</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Args<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an 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"c=
olor: #660;" class=3D"styled-by-prettify">){</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> =C2=A0</span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">new</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> T</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">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: #660;" class=3D"styled-by-prettify">}</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br>managed_ptr</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify">T</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">></span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> manage_new</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #606;"=
class=3D"styled-by-prettify">Args</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-pr=
ettify"> args</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =C2=
=A0<br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =C2=A0 <br>=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span></di=
v></code></div><div><br>I think that's acceptable in this case. =C2=A0<=
br></div><div><br></div><div>But is it possible for an IDE prompting a para=
m list when I typing , according to concept definition?<div class=3D"pretty=
print" 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"=
color: #000;" class=3D"styled-by-prettify">managed_new</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify"><</span><font color=3D"#0000=
00"><span style=3D"color: #000;" class=3D"styled-by-prettify">ABC</span></f=
ont><span style=3D"color: #660;" class=3D"styled-by-prettify">>(</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span></div></co=
de></div><br>I hope the IDE will prompt you with</div><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: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">int</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">int</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">double</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;"=
class=3D"styled-by-prettify">double</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">double</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">)</span></div></code></div><div>in this case?</div><div><br></div><div>=
<br></div><div><br><div><br></div><div><br><br>=E5=9C=A8 2017=E5=B9=B48=E6=
=9C=882=E6=97=A5=E6=98=9F=E6=9C=9F=E4=B8=89 UTC+8=E4=B8=8B=E5=8D=884:05:12=
=EF=BC=8CMagnus Fromreide=E5=86=99=E9=81=93=EF=BC=9A<blockquote class=3D"gm=
ail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc soli=
d;padding-left: 1ex;">On Tue, Aug 01, 2017 at 11:09:55PM -0700, wei zhang w=
rote:
<br>> c++ 1x has supported Variadic Template Args, like=20
<br>> template<typename ... Types> void aFunc(Types ... types){}
<br>> that let the args be any compositions of any Types. =C2=A0But howe=
ver, sometime=20
<br>> we are not hoping the args are anything, we may hope that the Type=
s should=20
<br>> follow some rules. =C2=A0In that case, template's deducing wil=
l help to report=20
<br>> compile error when your Args are wrong like cannot deducing to a f=
unction=20
<br>> according to the arguments.
<br>> Now I want an aggressive approach to achieve same purpose. =C2=A0I=
n my case, I=20
<br>> hope the compiler can already know the correct signature of Variad=
ic=20
<br>> Template Types before performing actual deducing.
<br>
<br>Could you please look at the concepts proposal and see if it is express=
ive
<br>enough for you.
<br>
<br>/MF
<br></blockquote></div></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/61698e62-6686-4153-8c72-d38592c41630%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/61698e62-6686-4153-8c72-d38592c41630=
%40isocpp.org</a>.<br />
------=_Part_6727_642357973.1501746600832--
------=_Part_6726_458666372.1501746600832--
.
Author: wei zhang <lala.willzhang@gmail.com>
Date: Thu, 3 Aug 2017 01:11:03 -0700 (PDT)
Raw View
------=_Part_6729_1116014842.1501747863523
Content-Type: multipart/alternative;
boundary="----=_Part_6730_707397806.1501747863524"
------=_Part_6730_707397806.1501747863524
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Further, I even hope IDE will catch the parameter name from the function=20
definition
Much further, I hope IDE will catch the comments in declaring function.
Because when I call managed_new<ABC>( ... ) I actually want to call new=20
ABC(...), the managed_new is just a wrapper of new, which make sure all the=
=20
pointers added into the manager are from immediate new.=20
Maybe, an IDE could investigate into the concept and list all possible=20
choices when dealing with variadic template types.
=E5=9C=A8 2017=E5=B9=B48=E6=9C=883=E6=97=A5=E6=98=9F=E6=9C=9F=E5=9B=9B UTC+=
8=E4=B8=8B=E5=8D=883:50:00=EF=BC=8Cwei zhang=E5=86=99=E9=81=93=EF=BC=9A
>
> I'm wondering how to write above manage_new<>() with Concept.
> template<T, typename ... Args> requires (Args .. args){ new T(args ...);=
=20
> }
> managed_ptr<T> manage_new(Args ... args) =20
> { =20
> }
>
>
> I think that's acceptable in this case. =20
>
> But is it possible for an IDE prompting a param list when I typing ,=20
> according to concept definition?
> managed_new<ABC>(=20
>
> I hope the IDE will prompt you with
> (int, int)
> (double, double, double)
> in this case?
>
>
> =20
>
>
>
>
> =E5=9C=A8 2017=E5=B9=B48=E6=9C=882=E6=97=A5=E6=98=9F=E6=9C=9F=E4=B8=89 UT=
C+8=E4=B8=8B=E5=8D=884:05:12=EF=BC=8CMagnus Fromreide=E5=86=99=E9=81=93=EF=
=BC=9A
>>
>> On Tue, Aug 01, 2017 at 11:09:55PM -0700, wei zhang wrote:=20
>> > c++ 1x has supported Variadic Template Args, like=20
>> > template<typename ... Types> void aFunc(Types ... types){}=20
>> > that let the args be any compositions of any Types. But however,=20
>> sometime=20
>> > we are not hoping the args are anything, we may hope that the Types=20
>> should=20
>> > follow some rules. In that case, template's deducing will help to=20
>> report=20
>> > compile error when your Args are wrong like cannot deducing to a=20
>> function=20
>> > according to the arguments.=20
>> > Now I want an aggressive approach to achieve same purpose. In my case=
,=20
>> I=20
>> > hope the compiler can already know the correct signature of Variadic=
=20
>> > Template Types before performing actual deducing.=20
>>
>> Could you please look at the concepts proposal and see if it is=20
>> expressive=20
>> enough for you.=20
>>
>> /MF=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/e22043f0-ad2e-47d3-a51b-a6c20f1a1f55%40isocpp.or=
g.
------=_Part_6730_707397806.1501747863524
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Further, I even hope IDE will catch the parameter name fro=
m the function definition<div>Much further, I hope IDE will catch the comme=
nts in declaring function.</div><div>Because when I call managed_new<ABC=
>( ... ) I actually want to call new ABC(...), the managed_new is just a=
wrapper of new, which make sure all the pointers added into the manager ar=
e from immediate new.=C2=A0</div><div><br></div><div>Maybe, an IDE could in=
vestigate into the concept and list all possible choices when dealing with =
variadic template types.</div><div><br><div><br><br>=E5=9C=A8 2017=E5=B9=B4=
8=E6=9C=883=E6=97=A5=E6=98=9F=E6=9C=9F=E5=9B=9B UTC+8=E4=B8=8B=E5=8D=883:50=
:00=EF=BC=8Cwei zhang=E5=86=99=E9=81=93=EF=BC=9A<blockquote class=3D"gmail_=
quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;pa=
dding-left: 1ex;"><div dir=3D"ltr">I'm wondering how to write above man=
age_new<>() with Concept.<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">template</span><span=
style=3D"color:#660"><</span><span style=3D"color:#000">T</span><span s=
tyle=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">typename</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#660">...</span><span style=3D"color:#000"> </span><span style=
=3D"color:#606">Args</span><span style=3D"color:#660">></span><span styl=
e=3D"color:#000"> requires </span><span style=3D"color:#660">(</span><span =
style=3D"color:#606">Args</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#660">..</span><span style=3D"color:#000"> args</span><span st=
yle=3D"color:#660">){</span><span style=3D"color:#000"> =C2=A0</span><span =
style=3D"color:#008">new</span><span style=3D"color:#000"> T</span><span st=
yle=3D"color:#660">(</span><span style=3D"color:#000">args </span><span sty=
le=3D"color:#660">...);</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#660">}</span><span style=3D"color:#000"><br>managed_ptr</span><=
span style=3D"color:#660"><</span><span style=3D"color:#000">T</span><sp=
an style=3D"color:#660">></span><span style=3D"color:#000"> manage_new</=
span><span style=3D"color:#660">(</span><span style=3D"color:#606">Args</sp=
an><span style=3D"color:#000"> </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"> =C2=A0<br></span><span style=3D"color:#660">{</s=
pan><span style=3D"color:#000"> =C2=A0 <br></span><span style=3D"color:#660=
">}</span><span style=3D"color:#000"><br><br></span></div></code></div><div=
><br>I think that's acceptable in this case. =C2=A0<br></div><div><br><=
/div><div>But is it possible for an IDE prompting a param list when I typin=
g , according to concept definition?<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><span style=3D"color:#000">managed_new</sp=
an><span style=3D"color:#660"><</span><font color=3D"#000000"><span styl=
e=3D"color:#000">ABC</span></font><span style=3D"color:#660">>(</span><s=
pan style=3D"color:#000"> </span></div></code></div><br>I hope the IDE will=
prompt you with</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><span style=3D"color:#660">(</span><span style=3D"color:=
#008">int</span><span style=3D"color:#660">,</span><span style=3D"color:#00=
0"> </span><span style=3D"color:#008">int</span><span style=3D"color:#660">=
)</span><span style=3D"color:#000"><br></span><span style=3D"color:#660">(<=
/span><span style=3D"color:#008">double</span><span style=3D"color:#660">,<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#008">double<=
/span><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span=
><span style=3D"color:#008">double</span><span style=3D"color:#660">)</span=
></div></code></div><div>in this case?</div><div><br></div><div><br></div><=
/div></blockquote><blockquote class=3D"gmail_quote" style=3D"margin: 0;marg=
in-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"=
ltr"><div>=C2=A0</div></div></blockquote><blockquote class=3D"gmail_quote" =
style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-l=
eft: 1ex;"><div dir=3D"ltr"><div><br><div><br></div><div><br><br>=E5=9C=A8 =
2017=E5=B9=B48=E6=9C=882=E6=97=A5=E6=98=9F=E6=9C=9F=E4=B8=89 UTC+8=E4=B8=8B=
=E5=8D=884:05:12=EF=BC=8CMagnus Fromreide=E5=86=99=E9=81=93=EF=BC=9A<blockq=
uote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:=
1px #ccc solid;padding-left:1ex">On Tue, Aug 01, 2017 at 11:09:55PM -0700, =
wei zhang wrote:
<br>> c++ 1x has supported Variadic Template Args, like=20
<br>> template<typename ... Types> void aFunc(Types ... types){}
<br>> that let the args be any compositions of any Types. =C2=A0But howe=
ver, sometime=20
<br>> we are not hoping the args are anything, we may hope that the Type=
s should=20
<br>> follow some rules. =C2=A0In that case, template's deducing wil=
l help to report=20
<br>> compile error when your Args are wrong like cannot deducing to a f=
unction=20
<br>> according to the arguments.
<br>> Now I want an aggressive approach to achieve same purpose. =C2=A0I=
n my case, I=20
<br>> hope the compiler can already know the correct signature of Variad=
ic=20
<br>> Template Types before performing actual deducing.
<br>
<br>Could you please look at the concepts proposal and see if it is express=
ive
<br>enough for you.
<br>
<br>/MF
<br></blockquote></div></div></div></blockquote></div></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/e22043f0-ad2e-47d3-a51b-a6c20f1a1f55%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/e22043f0-ad2e-47d3-a51b-a6c20f1a1f55=
%40isocpp.org</a>.<br />
------=_Part_6730_707397806.1501747863524--
------=_Part_6729_1116014842.1501747863523--
.
Author: Bengt Gustafsson <bengt.gustafsson@beamways.com>
Date: Thu, 3 Aug 2017 02:41:04 -0700 (PDT)
Raw View
------=_Part_6613_1744165675.1501753264894
Content-Type: multipart/alternative;
boundary="----=_Part_6614_1143240594.1501753264894"
------=_Part_6614_1143240594.1501753264894
Content-Type: text/plain; charset="UTF-8"
I think the main issue is to be able to show to users what types the
function expects. For instance in a n-dimensional matrix type it is more
illustrative to declare the operator() to take n size_ts than n anythings:
template<typename T, int RANK> class matrix {
template<???> T& operator()(size_t... ixes) { ... }
};
One obvious solution would be to just skip the "template<???>" part. I have
so far been siding with those who don't want terse template syntax to be as
terse as ever omitting the 'template' prefix, but I'm starting to change. I
mean, we already have this for lambdas:
auto lambda = [](auto... xs) {...}
and I think there is a contingency that want this:
void func(auto... xs) { ... }
as a shortcut for
template<typename... Ts> void func(Ts... xs) { ... }
so the problem with allowing
void func(size_t... xs) { ... }
would be that there is no obvious full template declaration that it is a
shortcut of. I can see three ways forward:
1. Do nothing, i.e. demand that my operator() is declared as with (auto...
xs) as parameters.
2. Allow void func(size_t... xs) { ... } without it being a terse form of
any full template declaration
3. Figure out a full template declaration it can be a shortcut of.
Personally I would prefer 3, but as of yet I don't have any reasonable
suggestion for a syntax.
I don't find this situation particularly appealing though:
void func(auto... xs); // ok
void func(Regular... xs); // ok
void func(size_t... xs); // error
but it seems this is the way we are heading in.
--
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/e9a3c2e8-c160-4718-a1a0-4e3188ca53e2%40isocpp.org.
------=_Part_6614_1143240594.1501753264894
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I think the main issue is to be able to show to users what=
types the function expects. For instance in a n-dimensional matrix type it=
is more illustrative to declare the operator() to take n size_ts than n an=
ythings:<div><br></div><div>=C2=A0 =C2=A0 template<typename T, int RANK&=
gt; class matrix {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0template<=
???> T& operator()(size_t... ixes) { ... }</div><div>=C2=A0 =C2=A0 }=
;</div><div><br></div><div>One obvious solution would be to just skip the &=
quot;template<???>" part. I have so far been siding with those w=
ho don't want terse template syntax to be as terse as ever omitting the=
'template' prefix, but I'm starting to change. I mean, we alre=
ady have this for lambdas:</div><div><br></div><div>=C2=A0 =C2=A0 auto lamb=
da =3D [](auto... xs) {...}</div><div><br></div><div>and I think there is a=
contingency that want this:</div><div><br></div><div>=C2=A0 =C2=A0 void fu=
nc(auto... xs) { ... }</div><div><br></div><div>as a shortcut for</div><div=
><br></div><div>=C2=A0 =C2=A0 template<typename... Ts> void func(Ts..=
.. xs) { ... }</div><div><br></div><div>so the problem with allowing</div><d=
iv><br></div><div>=C2=A0 =C2=A0 void func(size_t... xs) { ... }</div><div><=
br></div><div>would be that there is no obvious full template declaration t=
hat it is a shortcut of. I can see three ways forward:</div><div><br></div>=
<div>1. Do nothing, i.e. demand that my operator() is declared as with (aut=
o... xs) as parameters.</div><div><br></div><div>2. Allow void func(size_t.=
... xs) { ... } without it being a terse form of any full template declarati=
on</div><div><br></div><div>3. Figure out a full template declaration it ca=
n be a shortcut of.</div><div><br></div><div>Personally I would prefer 3, b=
ut as of yet I don't have any reasonable suggestion for a syntax.</div>=
<div><br></div><div>I don't find this situation particularly appealing =
though:</div><div><br></div><div>void func(auto... xs); =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 // ok</div><div>void func(Regular... xs); =C2=A0 // ok</div><div=
>void func(size_t... xs); =C2=A0 =C2=A0 =C2=A0// error</div><div><br></div>=
<div>but it seems this is the way we are heading in.</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/e9a3c2e8-c160-4718-a1a0-4e3188ca53e2%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/e9a3c2e8-c160-4718-a1a0-4e3188ca53e2=
%40isocpp.org</a>.<br />
------=_Part_6614_1143240594.1501753264894--
------=_Part_6613_1744165675.1501753264894--
.