Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-08-17 15:45:26


<Arturo_Cuebas_at_[hidden]> wrote in message
news:OF6215D845.F05336EF-ON86256EF3.005F9390-86256EF3.00613932_at_bpmicro.com...
> The program below contains a compile error. Following the program
you
> will find the typical fix then my idea for a library that
facilitates
> a syntactically prettier fix.

<snip>

> struct C
> {
> void F(char, char){}
> void F(int, int){}
> void F(char, int){}
> void F(char){}
> };
>
> int main()
> {
> C o;
> bind(
> C::F, // error: which C::F?
> &o, _1);
> }
>
> Typical solution:
>
> bind(static_cast<void (C::*)(char)>(C::F), &o, _1);

<snip>

> Here's my idea. If we had these:

<snip>

> ...etc; the bind call would look like this:
>
> bind(resolve_cast1<char>(C::F), &o, _1);

<snip>

> Is this worth the trouble?

I really like the idea. The main advantage is that you don't have to
repeat the class name, which may be long. E.g.

   void (symmetric_filter_adapter_impl::*close) () =
           &symmetric_filter_adapter_impl::close;

> Is it possible to implement a form without a number appended?

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.

Jonathan


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk