#include <iostream>
#include <vector>
#include <tuple>
#include <utility>
class ColumnBase {
std::string m_name;
public:
ColumnBase(const std::string& name) : m_name(name) {}
std::string name() { return m_name; }
};
template<class T>
class Column : public ColumnBase {
std::vector<T> m_items;
public:
Column(const std::string& name) :ColumnBase(name) {}
};
template<class... T>
class Table {
std::tuple<Column<T>...> m_columns;
template<std::size_t... index>
std::vector<ColumnBase*> columns_vec_helper(std::index_sequence<index...>) {
return { (&std::get<index>(m_columns))... };
}
public:
Table(Column<T>&&... columns) : m_columns(std::move(columns)...) {}
std::vector<ColumnBase*> columns_vec() {
return columns_vec_helper(std::make_index_sequence<sizeof...(T)>{});
}
};
int main() {
Table<std::size_t, std::string, int, int> t ({"id"}, {"name"}, {"x"}, {"y"});
for (const auto& colBase : t.columns_vec()) std::cout << "column " << colBase->name() << "\n";
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8dHVwbGU+CiNpbmNsdWRlIDx1dGlsaXR5PgoKICAgIGNsYXNzIENvbHVtbkJhc2UgewogICAgICBzdGQ6OnN0cmluZyBtX25hbWU7CiAgICBwdWJsaWM6CiAgICAgIENvbHVtbkJhc2UoY29uc3Qgc3RkOjpzdHJpbmcmIG5hbWUpIDogbV9uYW1lKG5hbWUpIHt9CiAgICAgIHN0ZDo6c3RyaW5nIG5hbWUoKSB7IHJldHVybiBtX25hbWU7IH0KICAgIH07CgogICAgdGVtcGxhdGU8Y2xhc3MgVD4KICAgIGNsYXNzIENvbHVtbiA6IHB1YmxpYyBDb2x1bW5CYXNlIHsKICAgICAgc3RkOjp2ZWN0b3I8VD4gbV9pdGVtczsKICAgICBwdWJsaWM6CiAgICAgIENvbHVtbihjb25zdCBzdGQ6OnN0cmluZyYgbmFtZSkgOkNvbHVtbkJhc2UobmFtZSkge30KICAgIH07CgogICAgdGVtcGxhdGU8Y2xhc3MuLi4gVD4KICAgIGNsYXNzIFRhYmxlIHsKICAgICAgc3Rk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