https://quuxplusone.github.io/blog/2020/11/24/type-erased-printable/
https://www.youtube.com/watch?v=tbUCHifyT24
#include "unique_printable.h" // see https://quuxplusone.github.io/blog/2020/11/24/type-erased-printable/
struct arrItem {
int key;
UniquePrintable item1;
UniquePrintable item2;
};
int main()
{
std::vector<arrItem> DataList;
DataList.push_back({ 0, 101, 102.10 });
DataList.push_back({ 1, 201, 202 });
DataList.push_back({ 2, 301, "hello world" }); // just for fun
for (auto& [key, item1, item2] : DataList) {
std::cout << "key: " << key << "; item1: " << item1 << "; item2: " << item2 << "\n";
}
}
Here is the C++17 code all worked out, and executing correctly, on Godbolt.
https://godbolt.org/z/bdPTT7oeo