Kevin
Kevin

Reputation: 18243

2-D vector of boost::variant in C++

I'm looking to store information from a data table with multiple rows and columns. Each column houses a differing type (int, double, std::string, etc), which would only be known at runtime.

Is a 2-d vector of boost::variant the best way, or are there better storing mechanisms to accomplish this?

Upvotes: 0

Views: 232

Answers (1)

Walter
Walter

Reputation: 45414

From your question it's not clear what you're actually looking for. The answer depends on various factors:

  • Assuming you have different types per column, are the types the same for all rows?

  • Are the types known at compile time or only at run-time?

In the simplest case of the types being known at compile time and being the same for all rows, why not simply use a custom class to represent a column or a std::tuple?

If the types are different between different columns, you must use a omnipotent type, such as boost::any. This may also be the easiest solution should the types only be known at run-time.

Upvotes: 2

Related Questions