p-ranav / tabulate

Table Maker for Modern C++
MIT License
1.91k stars 134 forks source link

Table: Provide size() function returning row counts #97

Closed edisonhello closed 1 year ago

edisonhello commented 1 year ago

Providing a function returning the number of rows is useful for me - I can format the table's rows at once after the table is built according to the number of rows, instead of setting a counter aside. I also saw that the size() function is already provided in TableInternal, so I think just returning the return value of table_->size() is fine.

Since there is no test, here's the testing code that I used to test the feature after I implemented it:

#include <cassert>
#include <iostream>
#include <tabulate/table.hpp>

int main() {
  tabulate::Table table;
  assert(table.size() == 0);
  table.add_row({"a", "b"});
  assert(table.size() == 1);
}

Also runs clang-format script in table.hpp file.