473,390 Members | 1,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 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 1189
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Michele Simionato | last post by:
I have read with interest the recent thread about closures. The funny thing is that the authors are arguing one against the other but I actually agree with all of them and I have a proposal that...
2
by: scummer | last post by:
Hi, I am having a problem with the httplib HTTPConnection object. While I can easily send requests that don't have any payload (ie. "get"), I encounter issues if I want to post xml data. If you...
1
by: Matt | last post by:
My problem is when the user click the submit button, it will launch another new window for the request page. I want to confirm we cannot use JavaScript open window functions to open a request page?...
1
by: Bhupesh Saini | last post by:
I am trying to call a ASPX page using HttpWebRequest class and pass cookie information to it. My ASPX pages gets called just fine, however none of the request cookies are available to the ASPX page....
0
by: martin | last post by:
Hi, I have created a namespace and a class as an additional project. I have made a referenece to my new namespace inside my web project and am happily using my new namespace. However I have one...
10
by: George G. | last post by:
Hi there, I am busy writing a new asp.net application and I am reusing some of my existing asp functions and methods in a user control. I need access to session, request and response in some of...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
2
by: Elliot Rodriguez | last post by:
I have a form that contains a mix of dynamic controls and declared controls. All of them are intrinsic .NET controls. Several functions within the page use Request.Form to query the value of the...
2
by: Steve R. Hastings | last post by:
While studying iterators and generator expressions, I started wishing I had some tools for processing the values. I wanted to be able to chain together a set of functions, sort of like the...
3
Airslash
by: Airslash | last post by:
Hello, currently I have 2 functions thatI'm trying to get to work together. Both functions make use of the Prototype library. The first function moves a div container with ID _tooltip on the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.