|
Boost : |
From: John Torjo (john.lists_at_[hidden])
Date: 2004-08-19 01:41:47
Peter Dimov wrote:
> Jonathan Turkanis wrote:
>
>> <Arturo_Cuebas_at_[hidden]> wrote in message
>> news:OF6215D845.F05336EF-ON86256EF3.005F9390-86256EF3.00613932_at_bpmicro.com...
>>
>>
>> I can do it with this syntax:
>>
>> boost::resolve_cast<int()>(&C::g);
>> boost::resolve_cast<int(int)>(&C::g);
>>
>> using function types as in Boost.Function. Your version would be the
>> 'portable syntax'.
>>
>>> Is there a name better than resolve_cast?
>>
>>
>> Sounds okay to me.
>>
>>> This was tested only in VC7.1.
>>
>>
>> You need to add &'s to former member function pointers. Otherwise it
>> looks okay to me. My version works on VC7.1, Como 4.3.3 and GCC 3.2.
>> I'll post it if there's interest.
>
>
> template<class F, class X> F X::* resolve_cast( F X::* pm ) { return pm; }
>
> looks like it ought to work. VC 7.1 doesn't like it, though. Neither
> does GCC 3.2.3. The online Comeau compiles it.
> _______________________________________________
How about having two or three more functions: mem_fn1, mem_fn2, mem_fn3
When you want a certain overload, you specify those parameters that
differenciate it from the other overloads, like:
class X {
1 void f(char);
2 int f(int);
3 int f(int, int);
4 int f(int, long);
5 int f(int, int, int);
6 long f(int, char, long);
};
mem_fn1<void>(&X::f); // selects 1
mem_fn2<any_param,any_param,int>(&X::f); // selects 3
mem_fn3<long>(&X::f); // selects 6
mem_fn3<int>(&X::f); // selects 5
Best,
John
-- John Torjo Freelancer -- john_at_[hidden] Contributing editor, C/C++ Users Journal -- "Win32 GUI Generics" -- generics & GUI do mix, after all -- http://www.torjo.com/win32gui/ -- v1.3beta released - check out splitter/simple_viewer, a File Explorer/Viewer all in about 200 lines of code! Professional Logging Solution for FREE -- http://www.torjo.com/code/logging.zip (logging - C++) -- http://www.torjo.com/logview/ (viewing/filtering - Win32) -- http://www.torjo.com/logbreak/ (debugging - Win32)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk