this will help While I don't believe that this restriction is strictly necessary, it is probably motivated by certain limitations in OCaml's module type system. Without going into too much technical detail, OCaml requires all intermediate module types to be expressible as syntactic signatures. But with functors, that sometimes isn't possible. For example, consider:
module Functor(X : sig end) = struct
type t = T of int
module Nested(Y : sig end) = struct let x = T 5 end
functor(Y : sig end) -> sig val x : Functor(struct end).t end (* not legal OCaml! *)
I hope this helps . In C++11, let's say I have a function that takes a functor/function and it forwards the arguments to that function. I can pass in a pointer to std::make_shared, which causes it to instantiate a class and call its contructor. But what is the equivalent to doing this with a raw operator new instead? It seems like std::allocator is what I should use, but the construct function there requires a pointer to the allocated memory. I can make it work by wrapping the new call into the template function new_object, but it seems like there should be a way for me to retrieve that function pointer directly. , Why not something like this?
I hope this helps you . boost::function, just like std::function requires a specific functor signature (in your case void(void*)), which is the signature it will try to call your functor with. That's why T is deduced as void and the compiler refuses to give you a void&, rightfully so. Your example is fundamentally add odds with itself, because if you want to have type erasure, you cannot have templates, as the compiler cannot know which templates to instantiate otherwise. Assume for a moment that boost::function could do what you want.
void foo(boost::function<magic> func)
double a = 5;
Can I pass a Functor class(that overloads operator()) to a function, that wants a function pointer? And how