|
Boost : |
From: Fabio Fracassi (f.fracassi_at_[hidden])
Date: 2008-08-29 10:51:00
Fabio Fracassi schrieb:
[...]
> what I have is something like this:
>
>
> template< typename Signature, class Reciever >
> void connect( const signal_id& id,
> const Signature& sig,
> const Reciever* rcv
> )
> {
> typedef ???? AdaptedSignature;
>
> get_signal< AdaptedSignature > ( id ) -> connect(boost::bind(sig,
> rcv, _1));
> }
>
>
> now this code is supposed to be called like this:
>
> connect( some_signal_id, &SomeClass::some_member, someClass_instance );
>
> where SomeClass::some_member has the same function signature as the
> signal which is associated with some_signal_id.
>
> e.g.
>
> boost::signal<void (bool)> signal;
>
> struct SomeClass {
> void some_member(bool b);
> };
>
> So my question is how can I construct the "AdaptedSignature" type from
> the template deduced "Signature"?
[...]
I solved the problem, and the solution is indeed boost::function_type.
The typedef in question looks like this:
namespace ft = boost::function_types;
namespace mpl = boost::mpl;
typedef ft::components<Signature>::types SigComp;
typedef mpl::advance<
mpl::begin< SigComp >::type, mpl::int_< 1 >
>::type
ClassPos;
typedef ft::function_type<
mpl::erase< SigComp, ClassPos >::type
>::type
AdaptedSignature;
Quite easy once one knows how.
The problem is that the function_type documentation is not very helpful.
I am missing at least some basic examples in the reference.
I found the necessary "examples" inside the Test suite.
It would suffice if some of the assertions from the test cases where
used to explain what each meta function is supposed to do.
for example I would have gasped the usage of function_type imeadiately
if there had been an example like
ft::function_type< mpl::vector<int,int,int> >::type
// type is a function type with the signature int (int, int)
or even more importantly for components:
class C
typedef C (C::*c_mem_func_ptr)(int) const;
ft::components<c_mem_func_ptr>::types // equals: mpl::vector<C,C const
&,int>
Hope that somebody may find this useful
Fabio
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk