From 8268065233914381879 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f78e5,9c3e31ec2c324b1d X-Google-Attributes: gidf78e5,public X-Google-ArrivalTime: 2001-03-27 15:52:24 PST Path: supernews.google.com!sn-xit-02!supernews.com!feed1.uncensored-news.com!news.alt.net!comp-std-cpp-robomod!not-for-mail From: gt5163b@prism.gatech.edu (Brian McNamara!) Newsgroups: comp.std.c++ Subject: Re: Suggestion: making bound member functions usable Date: Tue, 27 Mar 2001 17:49:22 CST Organization: Georgia Institute of Technology Lines: 52 Approved: Fergus Henderson , moderator of comp.std.c++ Message-ID: <99r8oo$smi$1@news-int.gatech.edu> References: <99ohfg$222a6$1@ID-82048.news.dfncis.de> <99opbs$73f$1@news-int.gatech.edu> <3AC0D0FE.51F14070@jps.net> Return-Path: X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov) X-Trace: news-int.gatech.edu 985736792 29394 130.207.165.22 (27 Mar 2001 23:46:32 GMT) X-Complaints-To: usenet@news.gatech.edu NNTP-Posting-Date: 27 Mar 2001 23:46:32 GMT X-Newsreader: trn 4.0-test72 (19 April 1999) Xref: supernews.google.com comp.std.c++:4041 Dennis Yelle once said: >"Brian McNamara!" wrote: >> Indeed. I wish I had a way to make this compile even: >> >> (&A::b)(a,3,_) >> >> by somehow invoking an implicit conversion so that it means >> >> X(&A::b).operator()(a,3,_) >> >> where X is a type admits an implicit conversion from the >> pointer-to-member-function. But I'm pretty sure that's impossible (and >> reasonably so). > >Sorry, I have no idea what you are saying here. >What is A? What is b? >And especially, what is X? A is a class, b is a method in that class, and X is a class which has a non-explicit constructor from &A::b. In other words, struct A { void b( int, int ) {} }; struct X { typedef void (A::*F)(int,int); F f; X( F g ) : f(g) {} // implicit conversion void operator()( A* a, int x, int y ) const { a->*f(x,y); } }; int main() { A a; // (&A::b)(&a,3,4); // would be nice (X(&A::b))(&a,3,4); // legal (X(&A::b)).operator()(&a,3,4); // more explicit version } Except that in the general case, we'd write 'X' as a template, so it can turn any class's (not just A's) member functions (not just two-argument int,int->void ones) into calls that take the receiver object as an extra parameter. -- Brian M. McNamara lorgon@acm.org : I am a parsing fool! ** Reduce - Reuse - Recycle ** : (Where's my medication? ;) ) --- [ comp.std.c++ is moderated. To submit articles, try just posting with ] [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://www.research.att.com/~austern/csc/faq.html ]