|
Boost Users : |
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-07-14 12:04:03
AMDG
Ruediger Berlich wrote:
> is it possible to get direct access to a function object encapsulated in
> boost::function ?
If you know that type of the function object, you can use target.
> And is it possible to determine whether boost::function
> has indeed stored a function object rather than, say, a function pointer ?
>
You can get the typeid of the type that a boost::function contains
using the function target_type.
#include <iostream>
#include <boost/function.hpp>
void f() {
std::cout << "Calling f" << std::endl;
}
int main() {
boost::function<void()> func = &f;
if(func.target_type() == typeid(void(*)())) {
func();
}
if(void(**target)() = func.target<void(*)()>()) {
(*target)();
}
}
In Christ,
Steven Watanabe
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net