Boost logo

Boost :

From: Rene Rivera (grafik.list_at_[hidden])
Date: 2005-05-20 12:54:10


David Abrahams wrote:
> David Abrahams <dave_at_[hidden]> writes:
>
>
>>I don't see how this can work.
>>
>>P p;
>>Q q;
>>
>>extern "C" int (*f1)(int)
>> = make_c_function<P,int(int)>(boost::bind(&p,P::foo,_1));
>>
>>extern "C" int (*f2)(int)
>> = make_c_function<P,int(int)>(boost::bind(&q,P::foo,_1));
>>
>>Don't these call the same function with the same stored data?
>>
>>ooh, sneaky idea... do you specailize a class template on the address
>>of the argument to make_c_function, thus generating unique functions?
>
>
> Oh, of course you can't do that; the argument is a runtime argument.
> How can it possibly work?

:-) You are correct it doesn't.. But I don't need it to. The key is that
the first template arg is really a GUID for the function. For me I
specify the GUID when I bind the various functions for the plugin
interface. The signature for the template function is:

template <
   typename InterfaceGUID, typename FunctionType, typename CallType>
typename
   detail::c_function_traits<InterfaceGUID,FunctionType>::function_type *
make_c_function(CallType call);

For your example you could do:

P p;
Q q;

extern "C" int (*f1)(int)
        = make_c_function<P,int(int)>(boost::bind(&p,P::foo,_1));

extern "C" int (*f2)(int)
        = make_c_function<Q,int(int)>(boost::bind(&q,Q::foo,_1));

Where P and Q will work as GUIDs if you have that single function in Q
and F. But more generally, one can use anonymous structs...

P p;
P q;

extern "C" int (*f1)(int)
   = make_c_function<
      struct call_0001,int(int)>(boost::bind(&p,P::foo,_1));

extern "C" int (*f1)(int)
   = make_c_function<
      struct call_0002,int(int)>(boost::bind(&q,P::foo,_1));

-- 
-- Grafik - Don't Assume Anything
-- Redshift Software, Inc. - http://redshift-software.com
-- rrivera/acm.org - grafik/redshift-software.com
-- 102708583/icq - grafikrobot/aim - Grafik/jabber.org

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