By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,389 Members | 1,881 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,389 IT Pros & Developers. It's quick & easy.

Odd help request (method functions)

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.