views:

165

answers:

1

Is it possible to access the arguments contained in a boost::function type?

I'd like to be able to retrieve the address of the function to be called, and the values of the arguments provided for that function.

+1  A: 

boost::function erases the implementation type, but if you know it, you can cast to it; since boost::function are comparable by value (== !=) the information is clearly available.

It looks like (from the function_base superclass of functionN) you can get the implementation object with:

f.target<concrete_functor_type>()

Which will return NULL if you provided the wrong concrete type.

Also in function_base (probably not helpful beyond the target method above):

public: // should be protected, but GCC 2.95.3 will fail to allow access
  detail::function::vtable_base* vtable;
  mutable detail::function::function_buffer functor;

vtable gives you access to:

      struct vtable_base
      {
        void (*manager)(const function_buffer& in_buffer, 
                        function_buffer& out_buffer, 
                        functor_manager_operation_type op);
      };

which can get you the typeid of the functor:

  case get_functor_type_tag:
    out_buffer.type.type = &typeid(F);
    out_buffer.type.const_qualified = in_buffer.obj_ref.is_const_qualified;
    out_buffer.type.volatile_qualified = in_buffer.obj_ref.is_volatile_qualified;
    return;
  }

function_buffer (functor) is only useful for refs to function objects, bound (this is fixed) member functions ptrs, and free functions, where you haven't bound any arguments

wrang-wrang