p-ranav / tabulate

Table Maker for Modern C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

element count and error checking

Bayemite opened this issue · comments

So I've just recently tried out this library today. Pretty good overall =)

Fairly surprised that there was no way to query the number of rows/columns/cells in a table.
Formatting the last row of a table, I tried a size() or a end()-1 function, like you would see in a standard container.
Frustrating to have to treat a class like a C array, with external variables to keep track of.
Would be good to have a shape() function for the row/column count.

Second, I didn't realise that a variable cell count for each row doesn't work. Something like:
table.add_row("Title").add_row("Key", "Value")
There was no indication that something was wrong until a very generic 'vector subscript out of range' assert triggered.
An assert (for example) within add_row(...) would help prevent a waste of time in the future..

Tables already have a shape() function: https://github.com/p-ranav/tabulate/blob/master/include/tabulate/table.hpp#L111

And yes, I can should throw an assert in add_row(...)

Sorry, I'm not being too clear...
What I meant by shape() was adding a new separate function that returns the column or row count.

So that callling shape() on:
table.add_row({"hi"}).add_row({"person"})
returns (1, 2)