Ad hoc polymorphism and heterogeneous containers with value semantics
问题 I have a number of unrelated types that all support the same operations through overloaded free functions (ad hoc polymorphism): struct A {}; void use(int x) { std::cout << "int = " << x << std::endl; } void use(const std::string& x) { std::cout << "string = " << x << std::endl; } void use(const A&) { std::cout << "class A" << std::endl; } As the title of the question implies, I want to store instances of those types in an heterogeneous container so that I can use() them no matter what