function-template

Is there a generic way to adapt a function template to be a polymorphic function object?

做~自己de王妃 提交于 2019-11-28 21:34:09
I have some function templates, for example template <typename T> void foo(T); template <typename T> void bar(T); // others and I need to pass each one to an algorithm that will call it with various types, e.g. template <typename F> void some_algorithm(F f) { // call f with argument of type int // call f with argument of type SomeClass // etc. } I can't pass in my function template uninstantiated, but I can't instantiate it with any specific type either because some_algorithm will need to call it with arguments of several different types. I could adapt my function templates to be polymorphic

Is there a generic way to adapt a function template to be a polymorphic function object?

穿精又带淫゛_ 提交于 2019-11-27 13:57:47
问题 I have some function templates, for example template <typename T> void foo(T); template <typename T> void bar(T); // others and I need to pass each one to an algorithm that will call it with various types, e.g. template <typename F> void some_algorithm(F f) { // call f with argument of type int // call f with argument of type SomeClass // etc. } I can't pass in my function template uninstantiated, but I can't instantiate it with any specific type either because some_algorithm will need to