100% Compile time typed dataframe like tables.
When accesing columns in a table-like structure we have two options. Create
a generic unordered_map<vector<T>>
approach or a struct of type listed below.
struct Table {
std::vector<int> id;
std::vector<std::string> name;
}
Both are problematic.
The first introduces the problem of attempting to get a column which doesn't exist resulting in undefined behaviour. The second introduces the problem of cluttering the namespace with many tables of different types.
TTable attempts to allow users to create tables on the fly and typing checking all inserts and columns. If a column is added midway through the code the column will only exist there and will be unaccessable before.
// Create all column types
using id_col = TTable::column<"id", int>;
using name_col = TTable::column<"name", std::string>;
// Create table with columns
auto table = TTable::create_table<id_col, name_col>();
TTable::push_back(table, 5, "test");
auto row = TTable::get_row(table, 0);
auto id = TTable::get_col_from_row<"id">(row);
auto name = TTable::get_col_from_row<"name">(row);
std::cout << "id: " << id << " name: " << name << std::endl;
using IdCol = TTable::Column<"id", int>;
auto table = TTable::create_table<IdCol>();
// Currently, unable to access age column
using AgeCol = TTable::Column<"age", int>;
auto newTable = TTable::add_column<AgeCol>(table);
// Now age column has been added to the type
git clone git@github.com:ewan15/TTable.git
add_subdirectory(TTable)
target_link_libraries(
<Your Project>
TTable
)
More examples in tests.