Help with templates

I am trying to make a table class that will be able to have multiple columns of data. I want it to have something to hold data (I was using a 2D vector for only one data type) in it, somewhat like a pair, but for any number of data types. The class is a template to make it generalized.

I have looked a little at variadic templates, but I don't know how to declare the vectors for each data types then.
What do you mean "for any number of data types"? How will you know how to handle the data you store?

If you truly mean it and have no doubt in your mind, you should check out boost::any
http://www.boost.org/doc/libs/1_56_0/doc/html/any.html
Last edited on
What I meant was, say if I want there to be two columns in my table, I can call Table <int, int>. Or, if there were 3 Table <string, int, int> and so on.

So, if I want to use boost::any to hold data,could I do it like so:
std::vector<std::vector<boost::any>> var

And push a vector of required type ( like vector<int> ) into var?
Oh, I see now. boost::any is not good for this situation - you would be able to have a different data type for each cell.

For this I would use a vector of tuples:

std::vector<std::tuple<std::string, int, int>> v;

This seems awfully similar to a database however - are you sure you don't want to use a real database?
Last edited on
Oh! That was exactly what I wanted to do.

I am making the class to be able to draw a table and take in input. I wanted to link the data to be output together.

Thanks a lot though!
Topic archived. No new replies allowed.