Odd help request (method functions)

D

daniel.w.gelder

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
 
K

Kanenas

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
 
D

daniel.w.gelder

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,665
Latest member
salkete

Latest Threads

Top