Class VariadicTable
-
template<class ...Ts>
class VariadicTable A class for “pretty printing” a table of data.
Requries C++11 (and nothing more)
It’s templated on the types that will be in each column (all values in a column must have the same type)
For instance, to use it with data that looks like: “Fred”, 193.4, 35, “Sam” with header names: “Name”, “Weight”, “Age”, “Brother”
You would invoke the table like so: VariadicTable<std::string, double, int, std::string> vt(“Name”, “Weight”, “Age”, “Brother”);
Then add the data to the table: vt.addRow(“Fred”, 193.4, 35, “Sam”);
And finally print it: vt.print();
Public Functions
-
inline VariadicTable(std::vector<std::string> headers, unsigned int static_column_size = 0, unsigned int cell_padding = 1)
Construct the table with headers
- Parameters:
headers – The names of the columns
static_column_size – The size of columns that can’t be found automatically
-
inline void addRow(Ts... entries)
Add a row of data
Easiest to use like: table.addRow({data1, data2, data3});
- Parameters:
data – A Tuple of data to add
-
template<typename StreamType>
inline void print(StreamType &stream) Pretty print the table of data
-
inline void setColumnFormat(const std::vector<VariadicTableColumnFormat> &column_format)
Set how to format numbers for each column
Note: this is ignored for std::string columns
@column_format The format for each column: MUST be the same length as the number of columns.
-
inline VariadicTable(std::vector<std::string> headers, unsigned int static_column_size = 0, unsigned int cell_padding = 1)