Topic: Proposal: implicit converstion of member function to
Author: wm2015email@gmail.com
Date: Sat, 19 Nov 2016 07:38:35 -0800 (PST)
Raw View
------=_Part_6482_1496490267.1479569915680
Content-Type: multipart/alternative;
boundary="----=_Part_6483_1801392335.1479569915680"
------=_Part_6483_1801392335.1479569915680
Content-Type: text/plain; charset=UTF-8
I always wonder why they just don't add an implicit type conversion for
"function pointers to non-static class methods" that automatically
creates a temporary function in the global scope that exactly matches the
function parameters
for the class method except its a regular non-class function, and then to
have this temporary global static
function call the specific non-static method in the class.
So if you request a pointer to a non-static class method in your code and
you use that pointer in the context
of needing a global function pointer to a static function, then the
compiler
returns the pointer to the temporary function created by the compiler, and
that
temporary function in turn calls the class method in a non-static context of
having access to all the public data members without needing to mark them
as static as well..
Seems this is the obvious solution to make inter-object communications
simple and elegant.
Lamba's just seems like a the less obvious solution in my opinion.
~Bill M.
Example:
typedef void (callback_t*)(Object* type, void* data)
void set_callback(callback_t* cb) {
}
class Foo : public Object{
public:
void do_something(Object* type, void* data);
int do_simething2() {
set_callback(&Foo::do_something); // Implicit function pointer
conversion function wrapper created by compiler...
}
};
//Function Created in secretly by compiler and function pointer returned
to call set_callback...
void __FOO__COMPILER_CREATED_do_something(Object* type, void* data) {
return
(this_pointer_from_calling_context_saved_by_compiler)->*do_something(type,
data);
}
// inside of class method FOO...
&Foo::do_something =>> &__FOO_COMPILER_CREATED_do_something;
--
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/31cd1b1d-25cc-4114-aa86-daa771b529ad%40isocpp.org.
------=_Part_6483_1801392335.1479569915680
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I always wonder why they just don't add an implicit ty=
pe conversion for "function pointers to non-static class methods"=
that automatically<br>creates a temporary function in the global scope tha=
t exactly matches the function parameters <br>for the class method except i=
ts a regular non-class function, and then to have this temporary global sta=
tic <br>function call the specific non-static method in the class.=C2=A0 <b=
r><br>So if you request a pointer to a non-static class method in your code=
and you use that pointer in the context<br>of needing a global function po=
inter to a static function, then the compiler <br>returns the pointer to th=
e temporary function created by the compiler, and that <br>temporary functi=
on in turn calls the class method in a non-static context of<br>having acce=
ss to all the public data members without needing to mark them as static as=
well..<br><br>Seems this is the obvious solution to make inter-object comm=
unications simple and elegant.<br>Lamba's just seems like a the less ob=
vious solution in my opinion.<br><br>~Bill M.<br><br>Example:<br><br>typede=
f void (callback_t*)(Object* type, void* data)<br><br>void set_callback(cal=
lback_t* cb) {<br>}<br><br>class Foo : public Object{<br>=C2=A0 public: <br=
>=C2=A0=C2=A0=C2=A0 void do_something(Object* type, void* data);<br><br>=C2=
=A0=C2=A0=C2=A0 int do_simething2() {<br>=C2=A0 =C2=A0 =C2=A0=C2=A0 set_cal=
lback(&Foo::do_something); =C2=A0=C2=A0=C2=A0=C2=A0 // Implicit functio=
n pointer conversion function wrapper created by compiler... <br>=C2=A0=C2=
=A0=C2=A0 }<br>};<br><br>//Function Created in secretly by compiler and fun=
ction pointer returned=C2=A0 to call set_callback...<br>void=C2=A0 __FOO__C=
OMPILER_CREATED_do_something(Object* type, void* data) {<br>=C2=A0=C2=A0 re=
turn (this_pointer_from_calling_context_saved_by_compiler)->*do_somethin=
g(type, data);<br>}<br><br>// inside of class method FOO...<br>&Foo::do=
_something =3D>> &__FOO_COMPILER_CREATED_do_something;<br><br><br=
><br><br><br><br><br></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/31cd1b1d-25cc-4114-aa86-daa771b529ad%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/31cd1b1d-25cc-4114-aa86-daa771b529ad=
%40isocpp.org</a>.<br />
------=_Part_6483_1801392335.1479569915680--
------=_Part_6482_1496490267.1479569915680--
.