In our C++ project I have a need in some combined data structure, I think it should be very similar to SQL table. I have a set of arrays (std::vectors) of a same size with different data types. e.g.:
time(int), X(double), Y(double), valid(boolean), number_of_measurements(int)
Let's pretend they are like a table, I need to have an access to them row-wise. For example I need a functionality to insert a row into an arbitrary position of the table which will cause a shift of all rows on one element down, kill row. I might need to sort the table by time, merge it with other tables of a same type.
Is there anything like this in C++ world?
Basically I need an universal solution, which supports any number of columns and rows. And of course the performance makes sense, so I prefer doing it rather in memory than in database.
UPDATE
I see many people are proposing to define a simple row structure and store it in a collection. No this is not going to fly as far as I have a need to frequently operate with columns. E.g. I may need to multiply the whole column or calculate a mean value out of it. I can even interpolate it or apply many different algorithms on a certain column.
And I want to avoid a situation when I extract a column to a vector, apply some algorithms on it and then put it back to a structure. It looks ugly, doesn't it?
I need more or less similar to this:
// Initializing: (three columns: time, X, Y)
table t("time", std::vector<int>(), "X", std::vector<double>(), "Y", std::vector<double>());
// inserting a row
t.insert_row( 1, 20.0f, 20.0f );
// accessing values:
t["time"][10] = 20;
// getting a column:
std::vector<int> time = t["time"];
// sorting
t.sort_by( "time" );
Any thoughts?