Probably more as a site note (curiosity if you will on a language level):
#include
int someFoo(int val) {return val + 5;}
void someMain() { boost::function
bptr = someFoo; int (*cptr)(int) = someFoo; bptr(5); cptr(5); if (bptr == cptr) printf("equal\n"); } The above code snipet does not compile as the types of bptr and cptr are not the same and thus their values cannot be compared although they are identical.
Even if bptr and cptr were both boost::function instances of the same type they would not compare.
OK.
I have not followed the C++ Spec evolution closely and am only familar with what appears to be the 98 spec. Are there any plans to uniformize this on the language level? This would allow interfacing C style code with the nice boost function pointers in a much cleaner way.
The limitation is not a language limitation but a library limitation. One cannot compare two boost::function objects because one cannot necessarily compare two arbitrary function objects, and even simpler versions (e.g., requiring that the boost::function targets have the same type) run into trouble.
True for comparison. However a C function pointer and a boost::function pointer with the same signature virtually have the same type. One would expect that a boost::function pointer should be castable to a C style pointer, as you can have std::string return a const char * pointer to its C style string. E.g. from the code snipet example: int (*cptr)(int) = bptr.fct_ptr(); (or some similar member). In the case of a bound function pointer, fct_ptr should arrange to return a pointer pointing to the function's closure, comprising thus the member function pointer plus eventually bound argument(s). The problem certainly is that boost::function is itself a class and you're handling instances of that class. Any access to its instance data has to happen through its members which seems to rule out the possibility of returning a static or C function compatible type with fct_ptr(). That is why I was not sure whether there is something missing in C++ where you can bind a member function to an instance of its declaring class and as a result getting a C-style compatible function pointer. -Thomas