Templatize functors

This speeds things up a bit (10%) in native code and has no effect on CLR code.  More importantly, it will make it easier to use a mix of function pointers, std::function, functor objects, or whatever we like.