MCPcopy Create free account
hub / github.com/p-ranav/tabulate / main

Function main

samples/streaming_rows.cpp:11–25  ·  view source on GitHub ↗

Demonstrates the fix for https://github.com/p-ranav/tabulate/issues/62: print the header immediately, then stream each row to stdout as soon as it's computed/added, instead of waiting to print the whole table at once. This only works with fixed column widths: a later, wider row can't retroactively widen a column whose border has already been printed.

Source from the content-addressed store, hash-verified

9// This only works with fixed column widths: a later, wider row can't
10// retroactively widen a column whose border has already been printed.
11int main() {
12 Table table;
13 table.add_row(Row_t{"Step", "Result"});
14 table.column(0).format().width(10);
15 table.column(1).format().width(12);
16 table.print_row(0); // print the header as soon as it's added
17
18 for (int step = 1; step <= 3; ++step) {
19 // ... pretend some computation happens here ...
20 table.add_row(Row_t{"Step " + std::to_string(step), step % 2 == 0 ? "OK" : "FAILED"});
21 table.print_row(table.size() - 1); // stream the new row immediately
22 }
23
24 table.print_bottom_border();
25}

Callers

nothing calls this directly

Calls 8

to_stringFunction · 0.50
add_rowMethod · 0.45
widthMethod · 0.45
formatMethod · 0.45
columnMethod · 0.45
print_rowMethod · 0.45
sizeMethod · 0.45
print_bottom_borderMethod · 0.45

Tested by

no test coverage detected