Topic: auto generate "reference" to overloaded functions


Author: wei zhang <lala.willzhang@gmail.com>
Date: Tue, 20 Jun 2017 20:45:06 -0700 (PDT)
Raw View
------=_Part_4619_663647524.1498016706259
Content-Type: multipart/alternative;
 boundary="----=_Part_4620_8141382.1498016706260"

------=_Part_4620_8141382.1498016706260
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable


Normally, we cannot refer to an overloaded function by only name, because=
=20
the function pointers are not the only one.  We must qualified the function=
=20
with the whole parameter list so as to get the actual one function pointer.
But we can create a functional class and wrap calling the overloaded=20
functions by overload operator ()
Here's the sample:


float Minus(float a, float b);
int   Minus=EF=BC=88int a, int b);
double  Minus(double a, double b);

template<Func, P1, P2 >=20
decltype(declval<Func>()(P1(), P2())) CheckAndDo( Func func,  P1 p1, P2 p2)
{
    if( p1 < 0 || p2 < 0 )
return decltype(Func(P1,P@)) 0;
    return func(p1, p2);
}

// compile failed, because Minus does not belong to an actual type.=20
Compiler cannot know which Function it is
CheckAndDo(&Minus, 10, 5);

//but still we can construct a type which can handle that=20
class Overload_Minus{
public:
    float operator()(float a, float b)
{
   return Minus(a,b);
}
int operator()(int a, int b)
{
return Minus(a,b);
}
double operator()(double a, double b)
{
return Minus(a,b);
}
};

// So that now we can calls
Overload_Minus minus;
int a =3D CheckAndDo(minus, 1, 2);


I think, this Overload_ class can be created anonymously by compiler=20
automatically.  Like

auto minus =3D overloaded Minus;  // here with a new keyword overloaded to=
=20
force tell compiler to create an annoymous Functional class
auto minus =3D Minus;   // or maybe, we can imply the creation of the=20
annoymouse class if there's no broken for c++ language

Further, we might do some filter when creating anonymous class
Sample:
Assumes we have 6 overloaded functions, by 2 groups.  We can filter them=20
with First Parameter Type
void print_to_strings(std::string &, int);
void print_to_strings(std::string &, double);
void print_to_strings(std::string &, float);

void print_to_strings(std::wstring &, int);
void print_to_strings(std::wstring &, double);
void print_to_strings(std::wstring &, float);

auto print_to_wstring =3D overloaded<T>(std::wstring&, T ) print_to_strings=
;
// print_to_wstring will now only refer to the last 3 functions. =20
// Any calls to print_to_wstring by a std::string will meet a compile=20
error, because it didn't provide operator(std::string, *)





--=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/61400f4e-62f6-48d0-94e7-c28ad49ef905%40isocpp.or=
g.

------=_Part_4620_8141382.1498016706260
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><div>Normally, we cannot refer to an overloaded functi=
on by only name, because the function pointers are not the only one. =C2=A0=
We must qualified the function with the whole parameter list so as to get t=
he actual one function pointer.</div><div>But we can create a functional cl=
ass and wrap calling the overloaded functions by overload operator ()</div>=
<div>Here&#39;s the sample:</div><div><br></div><div><br></div><div><div cl=
ass=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-c=
olor: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap=
: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><d=
iv class=3D"subprettyprint"><div class=3D"subprettyprint"><div class=3D"sub=
prettyprint"><font color=3D"#666600">float <span class=3D"Apple-tab-span" s=
tyle=3D"white-space:pre"> </span>Minus(float a, float b);</font></div><div =
class=3D"subprettyprint"><font color=3D"#666600">int =C2=A0 <span class=3D"=
Apple-tab-span" style=3D"white-space:pre"> </span>Minus=EF=BC=88int a, int =
b);</font></div><div class=3D"subprettyprint"><font color=3D"#666600">doubl=
e =C2=A0Minus(double a, double b);</font></div><div class=3D"subprettyprint=
"><font color=3D"#666600"><br></font></div><div class=3D"subprettyprint"><f=
ont color=3D"#666600">template&lt;Func, P1, P2 &gt;=C2=A0</font></div><div =
class=3D"subprettyprint"><font color=3D"#666600">decltype(declval&lt;Func&g=
t;()(P1(), P2())) CheckAndDo( Func func, =C2=A0P1 p1, P2 p2)</font></div><d=
iv class=3D"subprettyprint"><font color=3D"#666600">{</font></div><div clas=
s=3D"subprettyprint"><font color=3D"#666600">=C2=A0 =C2=A0 if( p1 &lt; 0 ||=
 p2 &lt; 0 )</font></div><div class=3D"subprettyprint"><font color=3D"#6666=
00"><span class=3D"Apple-tab-span" style=3D"white-space:pre">  </span>retur=
n decltype(Func(P1,P@)) 0;</font></div><div class=3D"subprettyprint"><font =
color=3D"#666600">=C2=A0 =C2=A0 return func(p1, p2);</font></div><div class=
=3D"subprettyprint"><font color=3D"#666600">}</font></div><div class=3D"sub=
prettyprint"><font color=3D"#666600"><br></font></div><div class=3D"subpret=
typrint"><font color=3D"#666600">// compile failed, because Minus does not =
belong to an actual type. Compiler cannot know which Function it is</font><=
/div><div class=3D"subprettyprint"><font color=3D"#666600">CheckAndDo(&amp;=
Minus, 10, 5);</font></div><div class=3D"subprettyprint"><font color=3D"#66=
6600"><br></font></div><div class=3D"subprettyprint"><font color=3D"#666600=
">//but still we can construct a type which can handle that=C2=A0</font></d=
iv><div class=3D"subprettyprint"><font color=3D"#666600">class Overload_Min=
us{</font></div><div class=3D"subprettyprint"><font color=3D"#666600">publi=
c:</font></div><div class=3D"subprettyprint"><font color=3D"#666600">=C2=A0=
 =C2=A0 float operator()(float a, float b)</font></div><div class=3D"subpre=
ttyprint"><font color=3D"#666600"><span class=3D"Apple-tab-span" style=3D"w=
hite-space:pre"> </span>{</font></div><div class=3D"subprettyprint"><font c=
olor=3D"#666600"><span class=3D"Apple-tab-span" style=3D"white-space:pre"> =
</span> =C2=A0 =C2=A0return Minus(a,b);</font></div><div class=3D"subpretty=
print"><font color=3D"#666600"><span class=3D"Apple-tab-span" style=3D"whit=
e-space:pre"> </span>}</font></div><div class=3D"subprettyprint"><span clas=
s=3D"Apple-tab-span" style=3D"white-space:pre"><font color=3D"#666600"> </f=
ont></span></div><div class=3D"subprettyprint"><font color=3D"#666600"><spa=
n class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>int operator()=
(int a, int b)</font></div><div class=3D"subprettyprint"><font color=3D"#66=
6600"><span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>{</f=
ont></div><div class=3D"subprettyprint"><font color=3D"#666600"><span class=
=3D"Apple-tab-span" style=3D"white-space:pre">  </span>return Minus(a,b);</=
font></div><div class=3D"subprettyprint"><font color=3D"#666600"><span clas=
s=3D"Apple-tab-span" style=3D"white-space:pre"> </span>}</font></div><div c=
lass=3D"subprettyprint"><span class=3D"Apple-tab-span" style=3D"white-space=
:pre"><font color=3D"#666600"> </font></span></div><div class=3D"subprettyp=
rint"><font color=3D"#666600"><span class=3D"Apple-tab-span" style=3D"white=
-space:pre"> </span>double operator()(double a, double b)</font></div><div =
class=3D"subprettyprint"><font color=3D"#666600"><span class=3D"Apple-tab-s=
pan" style=3D"white-space:pre"> </span>{</font></div><div class=3D"subprett=
yprint"><font color=3D"#666600"><span class=3D"Apple-tab-span" style=3D"whi=
te-space:pre">  </span>return Minus(a,b);</font></div><div class=3D"subpret=
typrint"><font color=3D"#666600"><span class=3D"Apple-tab-span" style=3D"wh=
ite-space:pre"> </span>}</font></div><div class=3D"subprettyprint"><font co=
lor=3D"#666600">};</font></div><div class=3D"subprettyprint"><font color=3D=
"#666600"><br></font></div><div class=3D"subprettyprint"><font color=3D"#66=
6600">// So that now we can calls</font></div><div class=3D"subprettyprint"=
><font color=3D"#666600">Overload_Minus minus;</font></div><div class=3D"su=
bprettyprint"><font color=3D"#666600">int a =3D CheckAndDo(minus, 1, 2);</f=
ont></div></div></div><div class=3D"subprettyprint"><br></div></div></code>=
</div></div><div><br></div><div>I think, this Overload_ class can be create=
d anonymously by compiler automatically. =C2=A0Like</div><div><br></div><di=
v>auto minus =3D overloaded Minus; =C2=A0// here with a new keyword overloa=
ded to force tell compiler to create an annoymous Functional class</div><di=
v>auto minus =3D Minus; =C2=A0 // or maybe, we can imply the creation of th=
e annoymouse class if there&#39;s no broken for c++ language</div><div><br>=
</div><div>Further, we might do some filter when creating anonymous class</=
div><div>Sample:</div><div>Assumes we have 6 overloaded functions, by 2 gro=
ups. =C2=A0We can filter them with First Parameter Type</div><div class=3D"=
subprettyprint" style=3D"font-family: monospace; background-color: rgb(250,=
 250, 250);"><font color=3D"#666600"><div class=3D"prettyprint" style=3D"ba=
ckground-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); borde=
r-style: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"p=
rettyprint"><div class=3D"subprettyprint">void print_to_strings(std::string=
 &amp;, int);<br></div></code><div class=3D"subprettyprint" style=3D"color:=
 rgb(34, 34, 34);"><font color=3D"#666600">void print_to_strings(std::strin=
g &amp;, double);</font></div><div class=3D"subprettyprint" style=3D"color:=
 rgb(34, 34, 34);"><font color=3D"#666600">void print_to_strings(std::strin=
g &amp;, float);</font></div><div class=3D"subprettyprint" style=3D"color: =
rgb(34, 34, 34);"><font color=3D"#666600"><br></font></div><div class=3D"su=
bprettyprint" style=3D"color: rgb(34, 34, 34);"><font color=3D"#666600">voi=
d print_to_strings(std::wstring &amp;, int);</font></div><div class=3D"subp=
rettyprint" style=3D"color: rgb(34, 34, 34);"><font color=3D"#666600">void =
print_to_strings(std::wstring &amp;, double);</font></div><div class=3D"sub=
prettyprint" style=3D"color: rgb(34, 34, 34);"><font color=3D"#666600">void=
 print_to_strings(std::wstring &amp;, float);</font></div><div class=3D"sub=
prettyprint" style=3D"color: rgb(34, 34, 34);"><font color=3D"#666600"><br>=
</font></div><div class=3D"subprettyprint" style=3D"color: rgb(34, 34, 34);=
"><font color=3D"#666600">auto print_to_wstring =3D overloaded&lt;T&gt;(std=
::wstring&amp;, T ) print_to_strings;<br>//=C2=A0</font><span style=3D"colo=
r: rgb(102, 102, 0);">print_to_wstring will now only refer to the last 3 fu=
nctions. =C2=A0<br>// Any calls to print_to_wstring by a std::string will m=
eet a compile error, because it didn&#39;t provide operator(std::string, *)=
<br></span></div></div><br><br></font></div><div class=3D"subprettyprint" s=
tyle=3D"font-family: monospace; background-color: rgb(250, 250, 250);"><fon=
t color=3D"#666600"><br></font></div><div class=3D"subprettyprint" style=3D=
"font-family: monospace; background-color: rgb(250, 250, 250);"><font color=
=3D"#666600"><br></font></div><div class=3D"subprettyprint" style=3D"font-f=
amily: monospace; background-color: rgb(250, 250, 250);"><font color=3D"#66=
6600"><br></font></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/61400f4e-62f6-48d0-94e7-c28ad49ef905%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/61400f4e-62f6-48d0-94e7-c28ad49ef905=
%40isocpp.org</a>.<br />

------=_Part_4620_8141382.1498016706260--

------=_Part_4619_663647524.1498016706259--

.


Author: wei zhang <lala.willzhang@gmail.com>
Date: Tue, 20 Jun 2017 21:03:27 -0700 (PDT)
Raw View
------=_Part_4891_1663473666.1498017807396
Content-Type: multipart/alternative;
 boundary="----=_Part_4892_1698553694.1498017807396"

------=_Part_4892_1698553694.1498017807396
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

The reason we must force programmer to virtual inherits a base class is tha=
t
The object system (or alike) requires that.  In game programming, we need=
=20
to manage a lot of objects.  Normally we would provide a BaseObject class=
=20
that would record basic informations like objId or other things.  However,=
=20
 if a user inherit the BaseObject accidently like polymorph style,  the=20
object manager will goes faulty.  So that the system requires the=20
BaseObject be virtual for anyone want to register the newed object into it.
Without the virtual keyword.  We still can require the same thing. it would=
=20
be like

class VirtualObject {
   int objid;=20
   ...
}
class BaseObject:public virtual VirtualObject
{
   // normally there's nothing
}

But first, it forces virtual without a noticable thing when user inherits=
=20
BaseObject.
Second, the functional class is VirtualObject, but user need to inherits=20
BaseObject. =20
Third, you cannot forbid user  inheirting VirtualObject directly.





=E5=9C=A8 2017=E5=B9=B46=E6=9C=8821=E6=97=A5=E6=98=9F=E6=9C=9F=E4=B8=89 UTC=
+8=E4=B8=8A=E5=8D=8811:45:06=EF=BC=8Cwei zhang=E5=86=99=E9=81=93=EF=BC=9A
>
>
> Normally, we cannot refer to an overloaded function by only name, because=
=20
> the function pointers are not the only one.  We must qualified the functi=
on=20
> with the whole parameter list so as to get the actual one function pointe=
r.
> But we can create a functional class and wrap calling the overloaded=20
> functions by overload operator ()
> Here's the sample:
>
>
> float Minus(float a, float b);
> int   Minus=EF=BC=88int a, int b);
> double  Minus(double a, double b);
>
> template<Func, P1, P2 >=20
> decltype(declval<Func>()(P1(), P2())) CheckAndDo( Func func,  P1 p1, P2 p=
2)
> {
>     if( p1 < 0 || p2 < 0 )
> return decltype(Func(P1,P@)) 0;
>     return func(p1, p2);
> }
>
> // compile failed, because Minus does not belong to an actual type.=20
> Compiler cannot know which Function it is
> CheckAndDo(&Minus, 10, 5);
>
> //but still we can construct a type which can handle that=20
> class Overload_Minus{
> public:
>     float operator()(float a, float b)
> {
>    return Minus(a,b);
> }
> int operator()(int a, int b)
> {
> return Minus(a,b);
> }
> double operator()(double a, double b)
> {
> return Minus(a,b);
> }
> };
>
> // So that now we can calls
> Overload_Minus minus;
> int a =3D CheckAndDo(minus, 1, 2);
>
>
> I think, this Overload_ class can be created anonymously by compiler=20
> automatically.  Like
>
> auto minus =3D overloaded Minus;  // here with a new keyword overloaded t=
o=20
> force tell compiler to create an annoymous Functional class
> auto minus =3D Minus;   // or maybe, we can imply the creation of the=20
> annoymouse class if there's no broken for c++ language
>
> Further, we might do some filter when creating anonymous class
> Sample:
> Assumes we have 6 overloaded functions, by 2 groups.  We can filter them=
=20
> with First Parameter Type
> void print_to_strings(std::string &, int);
> void print_to_strings(std::string &, double);
> void print_to_strings(std::string &, float);
>
> void print_to_strings(std::wstring &, int);
> void print_to_strings(std::wstring &, double);
> void print_to_strings(std::wstring &, float);
>
> auto print_to_wstring =3D overloaded<T>(std::wstring&, T ) print_to_strin=
gs;
> // print_to_wstring will now only refer to the last 3 functions. =20
> // Any calls to print_to_wstring by a std::string will meet a compile=20
> error, because it didn't provide operator(std::string, *)
>
>
>
>
>
>

--=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/d144d294-9b2d-4126-b717-064ae6821d04%40isocpp.or=
g.

------=_Part_4892_1698553694.1498017807396
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">The reason we must force programmer to virtual inherits a =
base class is that<div>The object system (or alike) requires that. =C2=A0In=
 game programming, we need to manage a lot of objects. =C2=A0Normally we wo=
uld provide a BaseObject class that would record basic informations like ob=
jId or other things. =C2=A0However, =C2=A0if a user inherit the BaseObject =
accidently like polymorph style, =C2=A0the object manager will goes faulty.=
 =C2=A0So that the system requires the BaseObject be virtual for anyone wan=
t to register the newed object into it.</div><div>Without the virtual keywo=
rd. =C2=A0We still can require the same thing. it would be like</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"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">class</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #606;" class=3D"styled-by-prettify">VirtualObje=
ct</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"><br>=C2=A0 =C2=A0</span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> objid</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</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">...</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">class</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prett=
ify">BaseObject</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">:</span><span style=3D"color: #008;" class=3D"styled-by-prettify">publ=
ic</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">virtual</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">VirtualObject</span><span st=
yle=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 =C2=A0</span><span style=3D"c=
olor: #800;" class=3D"styled-by-prettify">// normally there&#39;s nothing</=
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 styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span></div></code=
></div>But first, it forces virtual without a noticable thing when user inh=
erits BaseObject.</div><div>Second, the functional class is VirtualObject, =
but user need to inherits BaseObject. =C2=A0</div><div>Third, you cannot fo=
rbid user =C2=A0inheirting VirtualObject directly.</div><div><br></div><div=
><br></div><div><br></div><div><br><br>=E5=9C=A8 2017=E5=B9=B46=E6=9C=8821=
=E6=97=A5=E6=98=9F=E6=9C=9F=E4=B8=89 UTC+8=E4=B8=8A=E5=8D=8811:45:06=EF=BC=
=8Cwei zhang=E5=86=99=E9=81=93=EF=BC=9A<blockquote class=3D"gmail_quote" st=
yle=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-lef=
t: 1ex;"><div dir=3D"ltr"><br><div>Normally, we cannot refer to an overload=
ed function by only name, because the function pointers are not the only on=
e. =C2=A0We must qualified the function with the whole parameter list so as=
 to get the actual one function pointer.</div><div>But we can create a func=
tional class and wrap calling the overloaded functions by overload operator=
 ()</div><div>Here&#39;s the sample:</div><div><br></div><div><br></div><di=
v><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><=
div><div><div><font color=3D"#666600">float <span style=3D"white-space:pre"=
> </span>Minus(float a, float b);</font></div><div><font color=3D"#666600">=
int =C2=A0 <span style=3D"white-space:pre"> </span>Minus=EF=BC=88int a, int=
 b);</font></div><div><font color=3D"#666600">double =C2=A0Minus(double a, =
double b);</font></div><div><font color=3D"#666600"><br></font></div><div><=
font color=3D"#666600">template&lt;Func, P1, P2 &gt;=C2=A0</font></div><div=
><font color=3D"#666600">decltype(declval&lt;Func&gt;()(P1(), P2())) CheckA=
ndDo( Func func, =C2=A0P1 p1, P2 p2)</font></div><div><font color=3D"#66660=
0">{</font></div><div><font color=3D"#666600">=C2=A0 =C2=A0 if( p1 &lt; 0 |=
| p2 &lt; 0 )</font></div><div><font color=3D"#666600"><span style=3D"white=
-space:pre">  </span>return decltype(Func(P1,P@)) 0;</font></div><div><font=
 color=3D"#666600">=C2=A0 =C2=A0 return func(p1, p2);</font></div><div><fon=
t color=3D"#666600">}</font></div><div><font color=3D"#666600"><br></font><=
/div><div><font color=3D"#666600">// compile failed, because Minus does not=
 belong to an actual type. Compiler cannot know which Function it is</font>=
</div><div><font color=3D"#666600">CheckAndDo(&amp;Minus, 10, 5);</font></d=
iv><div><font color=3D"#666600"><br></font></div><div><font color=3D"#66660=
0">//but still we can construct a type which can handle that=C2=A0</font></=
div><div><font color=3D"#666600">class Overload_Minus{</font></div><div><fo=
nt color=3D"#666600">public:</font></div><div><font color=3D"#666600">=C2=
=A0 =C2=A0 float operator()(float a, float b)</font></div><div><font color=
=3D"#666600"><span style=3D"white-space:pre"> </span>{</font></div><div><fo=
nt color=3D"#666600"><span style=3D"white-space:pre"> </span> =C2=A0 =C2=A0=
return Minus(a,b);</font></div><div><font color=3D"#666600"><span style=3D"=
white-space:pre"> </span>}</font></div><div><span style=3D"white-space:pre"=
><font color=3D"#666600"> </font></span></div><div><font color=3D"#666600">=
<span style=3D"white-space:pre"> </span>int operator()(int a, int b)</font>=
</div><div><font color=3D"#666600"><span style=3D"white-space:pre"> </span>=
{</font></div><div><font color=3D"#666600"><span style=3D"white-space:pre">=
  </span>return Minus(a,b);</font></div><div><font color=3D"#666600"><span =
style=3D"white-space:pre"> </span>}</font></div><div><span style=3D"white-s=
pace:pre"><font color=3D"#666600"> </font></span></div><div><font color=3D"=
#666600"><span style=3D"white-space:pre"> </span>double operator()(double a=
, double b)</font></div><div><font color=3D"#666600"><span style=3D"white-s=
pace:pre"> </span>{</font></div><div><font color=3D"#666600"><span style=3D=
"white-space:pre">  </span>return Minus(a,b);</font></div><div><font color=
=3D"#666600"><span style=3D"white-space:pre"> </span>}</font></div><div><fo=
nt color=3D"#666600">};</font></div><div><font color=3D"#666600"><br></font=
></div><div><font color=3D"#666600">// So that now we can calls</font></div=
><div><font color=3D"#666600">Overload_Minus minus;</font></div><div><font =
color=3D"#666600">int a =3D CheckAndDo(minus, 1, 2);</font></div></div></di=
v><div><br></div></div></code></div></div><div><br></div><div>I think, this=
 Overload_ class can be created anonymously by compiler automatically. =C2=
=A0Like</div><div><br></div><div>auto minus =3D overloaded Minus; =C2=A0// =
here with a new keyword overloaded to force tell compiler to create an anno=
ymous Functional class</div><div>auto minus =3D Minus; =C2=A0 // or maybe, =
we can imply the creation of the annoymouse class if there&#39;s no broken =
for c++ language</div><div><br></div><div>Further, we might do some filter =
when creating anonymous class</div><div>Sample:</div><div>Assumes we have 6=
 overloaded functions, by 2 groups. =C2=A0We can filter them with First Par=
ameter Type</div><div style=3D"font-family:monospace;background-color:rgb(2=
50,250,250)"><font color=3D"#666600"><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>void print_to_strings(std::string &amp;, =
int);<br></div></code><div style=3D"color:rgb(34,34,34)"><font color=3D"#66=
6600">void print_to_strings(std::string &amp;, double);</font></div><div st=
yle=3D"color:rgb(34,34,34)"><font color=3D"#666600">void print_to_strings(s=
td::string &amp;, float);</font></div><div style=3D"color:rgb(34,34,34)"><f=
ont color=3D"#666600"><br></font></div><div style=3D"color:rgb(34,34,34)"><=
font color=3D"#666600">void print_to_strings(std::wstring &amp;, int);</fon=
t></div><div style=3D"color:rgb(34,34,34)"><font color=3D"#666600">void pri=
nt_to_strings(std::wstring &amp;, double);</font></div><div style=3D"color:=
rgb(34,34,34)"><font color=3D"#666600">void print_to_strings(std::wstring &=
amp;, float);</font></div><div style=3D"color:rgb(34,34,34)"><font color=3D=
"#666600"><br></font></div><div style=3D"color:rgb(34,34,34)"><font color=
=3D"#666600">auto print_to_wstring =3D overloaded&lt;T&gt;(std::wstring&amp=
;, T ) print_to_strings;<br>//=C2=A0</font><span style=3D"color:rgb(102,102=
,0)">print_to_wstring will now only refer to the last 3 functions. =C2=A0<b=
r>// Any calls to print_to_wstring by a std::string will meet a compile err=
or, because it didn&#39;t provide operator(std::string, *)<br></span></div>=
</div><br><br></font></div><div style=3D"font-family:monospace;background-c=
olor:rgb(250,250,250)"><font color=3D"#666600"><br></font></div><div style=
=3D"font-family:monospace;background-color:rgb(250,250,250)"><font color=3D=
"#666600"><br></font></div><div style=3D"font-family:monospace;background-c=
olor:rgb(250,250,250)"><font color=3D"#666600"><br></font></div></div></blo=
ckquote></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/d144d294-9b2d-4126-b717-064ae6821d04%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/d144d294-9b2d-4126-b717-064ae6821d04=
%40isocpp.org</a>.<br />

------=_Part_4892_1698553694.1498017807396--

------=_Part_4891_1663473666.1498017807396--

.


Author: Jakob Riedle <jakob.riedle@gmail.com>
Date: Wed, 21 Jun 2017 02:32:46 -0700 (PDT)
Raw View
------=_Part_4897_28217130.1498037566645
Content-Type: multipart/alternative;
 boundary="----=_Part_4898_165201512.1498037566645"

------=_Part_4898_165201512.1498037566645
Content-Type: text/plain; charset="UTF-8"

Hi Wei Zhang,

Great Idea. This has already been talked on e.g. by P0119
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0119r1.pdf>.

Cheers,
Jakob

--
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/6c4634c5-af3c-42b1-a00d-b02a584830aa%40isocpp.org.

------=_Part_4898_165201512.1498037566645
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><font color=3D"#666600">Hi Wei Zhang,</font></div><fo=
nt color=3D"#666600"><div><font color=3D"#666600"><br></font></div>Great Id=
ea. This has already been talked on e.g. by=C2=A0<a href=3D"http://www.open=
-std.org/jtc1/sc22/wg21/docs/papers/2016/p0119r1.pdf">P0119</a>.</font><div=
><br></div><div>Cheers,</div><div>Jakob</div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/6c4634c5-af3c-42b1-a00d-b02a584830aa%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/6c4634c5-af3c-42b1-a00d-b02a584830aa=
%40isocpp.org</a>.<br />

------=_Part_4898_165201512.1498037566645--

------=_Part_4897_28217130.1498037566645--

.