#include #include #include // For forward #include using namespace std ; // Primary template definition template class FunctionHandler { public: void handle(T val) { cout << "Handling generic type: " << typeid(T).name() << endl; } }; // Partial specialization for function types R(Args...) template class FunctionHandler { public: void handle(R (*func)(Args...)) { cout << "Handling function pointer with return type " << typeid(R).name() << " and arguments: "; // A more advanced implementation could iterate through Args... to print types cout << " (function pointer)" << endl; //callable_ptr(args...) } void handle(function func) { cout << "Handling function with return type " << typeid(R).name() << " and arguments: "; cout << " (function)" << endl; } }; // A sample function for demonstration int add(int a, int b) { return a + b; } void greet(const string& name) { cout << "Hello, " << name << "!" << endl; } int main() { // Generic type handling FunctionHandler intHandler; intHandler.handle(10); FunctionHandler stringHandler; stringHandler.handle("test"); // Function pointer handling FunctionHandler addHandler; addHandler.handle(&add); //function handling function greetFunc = greet ; FunctionHandler greetHandler; greetHandler.handle(greetFunc); return 0; }