472,110 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,110 software developers and data experts.

Odd help request (method functions)

Hey again.

I'm still working on my functor class, and now it works with method
functions too; you pass it the method function, as well as the object
you want to be 'this' when the method is called, for example:

struct Shill
{ void Conforming(string, int); }
Shill myShill;
functor<void (string,int)> theFunctor;
theFunctor = MethodWrap(&myShill, &Shill::Conforming);
theFunctor("Seven", 11);

MethodWrap is a namespace-level template function that gleans the
'Shill' type from the parameters you pass to it -- no need for a
separate function for everything!

My question is this. I would very much like to skip all that ugly
syntax in the method pointer usage, and pare it down to something
smooth like this:

theFunctor = myShill.Wrap(Conforming);

That resonates much better with me because
* it looks like the assignment it is
* the 'target' instance is naturally part of the syntax
* it doesn't need you to pass in the &Shill:: which should be
unnecessary since it must always match the 'target' anyway.

But about #3, C++'s syntax reader doesn't seem to have any idea what
Conforming is unless you pass &Shill:: in. So I'm trying to do it with
one of these Macros:

#define WrapShill(t, f) FunctionWrap(&t, &Shill::f)
theFunctor = WrapShill(&myShill, Conforming);

or

#define WrapShill(f) Wrap(&Shill:f)
theFunctor = myShill.WrapShill(Conforming);

But they're both full of redundancy thus ugly. Does anyone have an
alternate solution to get rid of the redundancy? I know this is kind of
petty but smoothing out syntax is my hobby right now.

Dan

Jul 23 '05 #1
2 1150
On 15 Apr 2005 22:33:43 -0700, da*************@gmail.com wrote:
Hey again.
[...]
My question is this. I would very much like to skip all that ugly
syntax in the method pointer usage, and pare it down to something
smooth like this:

theFunctor = myShill.Wrap(Conforming);
'Conforming' is 'Shill::Conforming' only within Shill's scope or the
scope of a descendant (as long as 'Conforming' isn't overridden or
defined in another ancestor of the descendant). Outside of Shill's
(or a descendant's) scope, it identifies something else. Otherwise,
what an identifier identified would be context sensitive beyond scope
sensitivity.
That resonates much better with me because
* it looks like the assignment it is
* the 'target' instance is naturally part of the syntax
* it doesn't need you to pass in the &Shill:: which should be
unnecessary since it must always match the 'target' anyway.

But about #3, C++'s syntax reader doesn't seem to have any idea what
Conforming is unless you pass &Shill:: in. So I'm trying to do it with
one of these Macros:

The only pure C++ (i.e. macro free) way to make 'Conforming'
synonymous with 'Shill::Conforming' outside of Shill's scope is to
have a definition such as:

void (Shill::* const Conforming)(string, int) = &Shill::Conforming;
...
theFunctor = myShill.Wrap(Conforming)

which is worse than using macros. If your compiler supports method
references, you can declare 'Conforming' as a 'Shell::&'. Inside the
scope of a descendant, a using declaration will "alias" the
identifier, but a using declaration for a member is only valid in such
a scope. If you don't want to give a fully qualified member
identifier, you're pretty much stuck with macros.

Personally, I don't find 'myShill.Wrap(&Shill::Conforming)' ugly.
Furthermore, a qualified identifier is necessary in cases where you
want to pass &Base::Conforming, where Base is, well, a base of Shill.

Kanenas
Jul 23 '05 #2
Thank you very much for your help.

For the record, I overloaded the class's &= operator to return a
functor.

So now the syntax is:

functor f = (myShill &=& Shill::Conforming)

Guess I'm "the creative type"...but I'm gonna look again at declaring
"Shill::&" a parameter..

Thanks
Dan

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by scummer | last post: by
reply views Thread by martin | last post: by
6 posts views Thread by Ammar | last post: by
2 posts views Thread by Elliot Rodriguez | last post: by
2 posts views Thread by Steve R. Hastings | last post: by
Airslash
3 posts views Thread by Airslash | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.