heterogeneous

Ad hoc polymorphism and heterogeneous containers with value semantics

荒凉一梦 提交于 2019-11-26 15:32:16
问题 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

Heterogeneous containers in C++

南楼画角 提交于 2019-11-26 12:24:19
I saw this nice graphic which classifies which STL container would suit based on different requirements of data such as: -- Fixed Size Vs Variable size -- Data of same tyme Vs different type -- Sorted Vs unsorted data -- Sequential Vs random access http://plasmahh.projectiwear.org/cce_clean.svg I notice in that image, that C++ STL there is no container which is Variable Size Heterogenous (data of different types). Doesn't C++ have something for this? PS - There can be many permutations made out the different properties of the containers and many others too might not be provided in STL. Fire

Heterogeneous containers in C++

懵懂的女人 提交于 2019-11-26 02:57:10
问题 I saw this nice graphic which classifies which STL container would suit based on different requirements of data such as: -- Fixed Size Vs Variable size -- Data of same tyme Vs different type -- Sorted Vs unsorted data -- Sequential Vs random access http://plasmahh.projectiwear.org/cce_clean.svg I notice in that image, that C++ STL there is no container which is Variable Size Heterogenous (data of different types). Doesn\'t C++ have something for this? PS - There can be many permutations made