mirror of
https://github.com/tdulcet/Table-and-Graph-Libs.git
synced 2025-05-05 21:41:12 +08:00
Restore support for C++14 (#1)
This commit is contained in:
parent
4c4a70ad6d
commit
1d6c53c985
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@ -27,9 +27,9 @@ jobs:
|
|||||||
$CXX --version
|
$CXX --version
|
||||||
- name: Script
|
- name: Script
|
||||||
run: |
|
run: |
|
||||||
$CXX -std=c++17 -Wall -g -Og -fsanitize=address,undefined tables.cpp -o tables
|
$CXX -std=c++14 -Wall -g -Og -fsanitize=address,undefined tables.cpp -o tables
|
||||||
./tables
|
./tables
|
||||||
$CXX -std=c++17 -Wall -g -Og -fsanitize=address,undefined graphs.cpp -o graphs
|
$CXX -std=c++14 -Wall -g -Og -fsanitize=address,undefined graphs.cpp -o graphs
|
||||||
./graphs
|
./graphs
|
||||||
- name: Cppcheck
|
- name: Cppcheck
|
||||||
run: cppcheck --enable=all .
|
run: cppcheck --enable=all .
|
||||||
|
@ -13,12 +13,12 @@ install:
|
|||||||
- sudo apt-get -yqq update
|
- sudo apt-get -yqq update
|
||||||
- sudo apt-get -yqq install cppcheck
|
- sudo apt-get -yqq install cppcheck
|
||||||
script:
|
script:
|
||||||
- g++ -std=c++17 -Wall -g -Og -fsanitize=address,undefined tables.cpp -o gcc_tables
|
- g++ -std=c++14 -Wall -g -Og -fsanitize=address,undefined tables.cpp -o gcc_tables
|
||||||
- ./gcc_tables
|
- ./gcc_tables
|
||||||
- g++ -std=c++17 -Wall -g -Og -fsanitize=address,undefined graphs.cpp -o gcc_graphs
|
- g++ -std=c++14 -Wall -g -Og -fsanitize=address,undefined graphs.cpp -o gcc_graphs
|
||||||
- ./gcc_graphs
|
- ./gcc_graphs
|
||||||
- clang++ -std=c++17 -Wall -g -Og -fsanitize=address,undefined,integer tables.cpp -o clang_tables
|
- clang++ -std=c++14 -Wall -g -Og -fsanitize=address,undefined,integer tables.cpp -o clang_tables
|
||||||
- ./clang_tables
|
- ./clang_tables
|
||||||
- clang++ -std=c++17 -Wall -g -Og -fsanitize=address,undefined,integer graphs.cpp -o clang_graphs
|
- clang++ -std=c++14 -Wall -g -Og -fsanitize=address,undefined,integer graphs.cpp -o clang_graphs
|
||||||
- ./clang_graphs
|
- ./clang_graphs
|
||||||
- cppcheck --enable=all .
|
- cppcheck --enable=all .
|
||||||
|
14
README.md
14
README.md
@ -17,14 +17,14 @@ See the [python](python) directory for Python ports of the libraries.
|
|||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
Requires support for C++17. See the [tables.hpp](tables.hpp) file for full usage information.
|
Requires support for C++14. See the [tables.hpp](tables.hpp) file for full usage information.
|
||||||
|
|
||||||
Complete versions of all of the examples below and more can be found in the [tables.cpp](tables.cpp) file.
|
Complete versions of all of the examples below and more can be found in the [tables.cpp](tables.cpp) file.
|
||||||
|
|
||||||
Compile with:
|
Compile with:
|
||||||
|
|
||||||
GCC: `g++ -std=c++17 -Wall -g -O3 tables.cpp -o tables`\
|
GCC: `g++ -std=c++14 -Wall -g -O3 tables.cpp -o tables`\
|
||||||
Clang: `clang++ -std=c++17 -Wall -g -O3 tables.cpp -o tables`
|
Clang: `clang++ -std=c++14 -Wall -g -O3 tables.cpp -o tables`
|
||||||
|
|
||||||
Run with: `./tables`
|
Run with: `./tables`
|
||||||
|
|
||||||
@ -267,7 +267,7 @@ template <typename T>
|
|||||||
bool compare(const T &a, const T &b)
|
bool compare(const T &a, const T &b)
|
||||||
{
|
{
|
||||||
if (a[sortdimension] == b[sortdimension])
|
if (a[sortdimension] == b[sortdimension])
|
||||||
for (int i = 0; i < size(a); ++i)
|
for (int i = 0; i < tables::size(a); ++i)
|
||||||
if (sortdimension != i and a[i] != b[i])
|
if (sortdimension != i and a[i] != b[i])
|
||||||
return a[i] < b[i];
|
return a[i] < b[i];
|
||||||
|
|
||||||
@ -512,13 +512,13 @@ Values:
|
|||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
Requires support for C++17. See the [graphs.hpp](graphs.hpp) file for full usage information.
|
Requires support for C++14. See the [graphs.hpp](graphs.hpp) file for full usage information.
|
||||||
|
|
||||||
Complete versions of all of the examples below and more can be found in the [graphs.cpp](graphs.cpp) file.
|
Complete versions of all of the examples below and more can be found in the [graphs.cpp](graphs.cpp) file.
|
||||||
|
|
||||||
Compile with:
|
Compile with:
|
||||||
GCC: `g++ -std=c++17 -Wall -g -O3 graphs.cpp -o graphs`\
|
GCC: `g++ -std=c++14 -Wall -g -O3 graphs.cpp -o graphs`\
|
||||||
Clang: `clang++ -std=c++17 -Wall -g -O3 graphs.cpp -o graphs`
|
Clang: `clang++ -std=c++14 -Wall -g -O3 graphs.cpp -o graphs`
|
||||||
|
|
||||||
Run with: `./graphs`
|
Run with: `./graphs`
|
||||||
|
|
||||||
|
18
graphs.cpp
18
graphs.cpp
@ -1,6 +1,6 @@
|
|||||||
// Teal Dulcet, CS546
|
// Teal Dulcet, CS546
|
||||||
|
|
||||||
// Compile: g++ -Wall -g -O3 -std=c++17 graphs.cpp -o graphs
|
// Compile: g++ -Wall -g -O3 -std=c++14 graphs.cpp -o graphs
|
||||||
|
|
||||||
// Run: ./graphs
|
// Run: ./graphs
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ int main()
|
|||||||
|
|
||||||
graphs::options aoptions;
|
graphs::options aoptions;
|
||||||
|
|
||||||
for (unsigned int k = 0; k < size(graphs::styles); ++k)
|
for (unsigned int k = 0; k < graphs::size(graphs::styles); ++k)
|
||||||
{
|
{
|
||||||
aoptions.style = k;
|
aoptions.style = k;
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ int main()
|
|||||||
|
|
||||||
graphs::options aoptions;
|
graphs::options aoptions;
|
||||||
|
|
||||||
for (unsigned int k = 0; k < size(graphs::styles); ++k)
|
for (unsigned int k = 0; k < graphs::size(graphs::styles); ++k)
|
||||||
{
|
{
|
||||||
aoptions.style = k;
|
aoptions.style = k;
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ int main()
|
|||||||
|
|
||||||
graphs::options aoptions;
|
graphs::options aoptions;
|
||||||
|
|
||||||
for (unsigned int k = 0; k < size(graphs::styles); ++k)
|
for (unsigned int k = 0; k < graphs::size(graphs::styles); ++k)
|
||||||
{
|
{
|
||||||
aoptions.style = k;
|
aoptions.style = k;
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ int main()
|
|||||||
{
|
{
|
||||||
graphs::options aoptions;
|
graphs::options aoptions;
|
||||||
|
|
||||||
for (unsigned int k = 0; k < size(graphs::styles); ++k)
|
for (unsigned int k = 0; k < graphs::size(graphs::styles); ++k)
|
||||||
{
|
{
|
||||||
aoptions.style = k;
|
aoptions.style = k;
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ int main()
|
|||||||
|
|
||||||
graphs::options aoptions;
|
graphs::options aoptions;
|
||||||
|
|
||||||
for (unsigned int k = 0; k < size(graphs::styles); ++k)
|
for (unsigned int k = 0; k < graphs::size(graphs::styles); ++k)
|
||||||
{
|
{
|
||||||
aoptions.style = k;
|
aoptions.style = k;
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ int main()
|
|||||||
|
|
||||||
graphs::options aoptions;
|
graphs::options aoptions;
|
||||||
|
|
||||||
for (unsigned int k = 0; k < size(graphs::styles); ++k)
|
for (unsigned int k = 0; k < graphs::size(graphs::styles); ++k)
|
||||||
{
|
{
|
||||||
aoptions.style = k;
|
aoptions.style = k;
|
||||||
|
|
||||||
@ -162,7 +162,7 @@ int main()
|
|||||||
|
|
||||||
graphs::options aoptions;
|
graphs::options aoptions;
|
||||||
|
|
||||||
for (unsigned int k = 0; k < size(graphs::styles); ++k)
|
for (unsigned int k = 0; k < graphs::size(graphs::styles); ++k)
|
||||||
{
|
{
|
||||||
aoptions.style = k;
|
aoptions.style = k;
|
||||||
|
|
||||||
@ -181,7 +181,7 @@ int main()
|
|||||||
aoptions.axisunitslabel = false;
|
aoptions.axisunitslabel = false;
|
||||||
// graphs::options aoptions{.axisunitslabel = false};
|
// graphs::options aoptions{.axisunitslabel = false};
|
||||||
|
|
||||||
for (unsigned int k = 0; k < size(graphs::styles); ++k)
|
for (unsigned int k = 0; k < graphs::size(graphs::styles); ++k)
|
||||||
{
|
{
|
||||||
aoptions.style = k;
|
aoptions.style = k;
|
||||||
|
|
||||||
|
28
graphs.hpp
28
graphs.hpp
@ -55,6 +55,12 @@ namespace graphs
|
|||||||
|
|
||||||
const options defaultoptions;
|
const options defaultoptions;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
auto size(const T &array)
|
||||||
|
{
|
||||||
|
return distance(begin(array), end(array));
|
||||||
|
}
|
||||||
|
|
||||||
// Number of columns needed to represent the string
|
// Number of columns needed to represent the string
|
||||||
// Adapted from: https://stackoverflow.com/a/31124065
|
// Adapted from: https://stackoverflow.com/a/31124065
|
||||||
int strcol(const char *const str)
|
int strcol(const char *const str)
|
||||||
@ -159,7 +165,7 @@ namespace graphs
|
|||||||
long double intpart = 0;
|
long double intpart = 0;
|
||||||
long double fractionpart = abs(modf(label, &intpart));
|
long double fractionpart = abs(modf(label, &intpart));
|
||||||
|
|
||||||
for (unsigned int i = 0; i < size(fractions) and !output; ++i)
|
for (unsigned int i = 0; i < graphs::size(fractions) and !output; ++i)
|
||||||
{
|
{
|
||||||
if (abs(fractionpart - fractionvalues[i]) < DBL_EPSILON)
|
if (abs(fractionpart - fractionvalues[i]) < DBL_EPSILON)
|
||||||
{
|
{
|
||||||
@ -217,7 +223,7 @@ namespace graphs
|
|||||||
// Output graph
|
// Output graph
|
||||||
int graph(const size_t height, const size_t width, const long double xmin, const long double xmax, const long double ymin, const long double ymax, const vector<vector<unsigned short>> &array, const options &aoptions)
|
int graph(const size_t height, const size_t width, const long double xmin, const long double xmax, const long double ymin, const long double ymax, const vector<vector<unsigned short>> &array, const options &aoptions)
|
||||||
{
|
{
|
||||||
if (!size(array))
|
if (!graphs::size(array))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
const bool border = aoptions.border;
|
const bool border = aoptions.border;
|
||||||
@ -226,7 +232,7 @@ namespace graphs
|
|||||||
const char *const title = aoptions.title;
|
const char *const title = aoptions.title;
|
||||||
const unsigned int style = aoptions.style;
|
const unsigned int style = aoptions.style;
|
||||||
|
|
||||||
if (style >= size(styles))
|
if (style >= graphs::size(styles))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (height == 0)
|
if (height == 0)
|
||||||
@ -492,12 +498,12 @@ namespace graphs
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
int arrays(size_t height, size_t width, long double xmin, long double xmax, long double ymin, long double ymax, const T &arrays, const options &aoptions = defaultoptions)
|
int arrays(size_t height, size_t width, long double xmin, long double xmax, long double ymin, long double ymax, const T &arrays, const options &aoptions = defaultoptions)
|
||||||
{
|
{
|
||||||
if (!size(arrays))
|
if (!graphs::size(arrays))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (!all_of(begin(arrays), end(arrays), [](const auto &array)
|
if (!all_of(begin(arrays), end(arrays), [](const auto &array)
|
||||||
{ return all_of(begin(array), end(array), [](const auto &x)
|
{ return all_of(begin(array), end(array), [](const auto &x)
|
||||||
{ return size(x) == 2; }); }))
|
{ return graphs::size(x) == 2; }); }))
|
||||||
{
|
{
|
||||||
cerr << "Error: The arrays must have two columns.";
|
cerr << "Error: The arrays must have two columns.";
|
||||||
return 1;
|
return 1;
|
||||||
@ -505,7 +511,7 @@ namespace graphs
|
|||||||
|
|
||||||
const unsigned int color = aoptions.color;
|
const unsigned int color = aoptions.color;
|
||||||
|
|
||||||
if (color >= size(colors))
|
if (color >= graphs::size(colors))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
struct winsize w;
|
struct winsize w;
|
||||||
@ -571,12 +577,12 @@ namespace graphs
|
|||||||
|
|
||||||
vector<vector<unsigned short>> aarray(width, vector<unsigned short>(height, 0));
|
vector<vector<unsigned short>> aarray(width, vector<unsigned short>(height, 0));
|
||||||
|
|
||||||
for (unsigned int j = 0; j < size(arrays); ++j)
|
for (unsigned int j = 0; j < graphs::size(arrays); ++j)
|
||||||
{
|
{
|
||||||
auto array = arrays[j];
|
auto array = arrays[j];
|
||||||
const unsigned int color = (j % (size(colors) - 2)) + 3;
|
const unsigned int color = (j % (graphs::size(colors) - 2)) + 3;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < size(array); ++i)
|
for (unsigned int i = 0; i < graphs::size(array); ++i)
|
||||||
{
|
{
|
||||||
if (array[i][0] >= xmin and array[i][0] < xmax and array[i][1] >= ymin and array[i][1] < ymax)
|
if (array[i][0] >= xmin and array[i][0] < xmax and array[i][1] >= ymin and array[i][1] < ymax)
|
||||||
{
|
{
|
||||||
@ -627,7 +633,7 @@ namespace graphs
|
|||||||
{
|
{
|
||||||
const unsigned int color = aoptions.color;
|
const unsigned int color = aoptions.color;
|
||||||
|
|
||||||
if (color >= size(colors))
|
if (color >= graphs::size(colors))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (numfunctions == 0)
|
if (numfunctions == 0)
|
||||||
@ -680,7 +686,7 @@ namespace graphs
|
|||||||
|
|
||||||
for (unsigned int j = 0; j < numfunctions; ++j)
|
for (unsigned int j = 0; j < numfunctions; ++j)
|
||||||
{
|
{
|
||||||
unsigned short acolor = numfunctions == 1 ? color + 1 : (j % (size(colors) - 2)) + 3;
|
unsigned short acolor = numfunctions == 1 ? color + 1 : (j % (graphs::size(colors) - 2)) + 3;
|
||||||
|
|
||||||
for (long double i = 0; i < rows; i += 0.5)
|
for (long double i = 0; i < rows; i += 0.5)
|
||||||
{
|
{
|
||||||
|
38
tables.cpp
38
tables.cpp
@ -1,6 +1,6 @@
|
|||||||
// Teal Dulcet, CS546
|
// Teal Dulcet, CS546
|
||||||
|
|
||||||
// Compile: g++ -Wall -g -O3 -std=c++17 tables.cpp -o tables
|
// Compile: g++ -Wall -g -O3 -std=c++14 tables.cpp -o tables
|
||||||
|
|
||||||
// Run: ./tables
|
// Run: ./tables
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ int main()
|
|||||||
|
|
||||||
tables::options aoptions;
|
tables::options aoptions;
|
||||||
|
|
||||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||||
{
|
{
|
||||||
aoptions.style = k;
|
aoptions.style = k;
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ int main()
|
|||||||
|
|
||||||
tables::options aoptions;
|
tables::options aoptions;
|
||||||
|
|
||||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||||
{
|
{
|
||||||
aoptions.style = k;
|
aoptions.style = k;
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ int main()
|
|||||||
|
|
||||||
tables::options aoptions;
|
tables::options aoptions;
|
||||||
|
|
||||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||||
{
|
{
|
||||||
aoptions.style = k;
|
aoptions.style = k;
|
||||||
|
|
||||||
@ -155,7 +155,7 @@ int main()
|
|||||||
|
|
||||||
tables::options aoptions;
|
tables::options aoptions;
|
||||||
|
|
||||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||||
{
|
{
|
||||||
aoptions.style = k;
|
aoptions.style = k;
|
||||||
|
|
||||||
@ -179,7 +179,7 @@ int main()
|
|||||||
|
|
||||||
tables::options aoptions;
|
tables::options aoptions;
|
||||||
|
|
||||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||||
{
|
{
|
||||||
aoptions.style = k;
|
aoptions.style = k;
|
||||||
|
|
||||||
@ -195,7 +195,7 @@ int main()
|
|||||||
|
|
||||||
tables::options aoptions;
|
tables::options aoptions;
|
||||||
|
|
||||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||||
{
|
{
|
||||||
aoptions.style = k;
|
aoptions.style = k;
|
||||||
|
|
||||||
@ -217,7 +217,7 @@ int main()
|
|||||||
aoptions.headercolumn = true;
|
aoptions.headercolumn = true;
|
||||||
// tables::options aoptions{.headerrow = true, .headercolumn = true};
|
// tables::options aoptions{.headerrow = true, .headercolumn = true};
|
||||||
|
|
||||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||||
{
|
{
|
||||||
aoptions.style = k;
|
aoptions.style = k;
|
||||||
|
|
||||||
@ -236,7 +236,7 @@ int main()
|
|||||||
aoptions.headercolumn = true;
|
aoptions.headercolumn = true;
|
||||||
// tables::options aoptions{.headerrow = true, .headercolumn = true};
|
// tables::options aoptions{.headerrow = true, .headercolumn = true};
|
||||||
|
|
||||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||||
{
|
{
|
||||||
aoptions.style = k;
|
aoptions.style = k;
|
||||||
|
|
||||||
@ -263,7 +263,7 @@ int main()
|
|||||||
aoptions.headercolumn = true;
|
aoptions.headercolumn = true;
|
||||||
// tables::options aoptions{.headerrow = true, .headercolumn = true};
|
// tables::options aoptions{.headerrow = true, .headercolumn = true};
|
||||||
|
|
||||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||||
{
|
{
|
||||||
aoptions.style = k;
|
aoptions.style = k;
|
||||||
|
|
||||||
@ -286,7 +286,7 @@ int main()
|
|||||||
vector<string> aheadercolumn(headerrow, headerrow + 1);
|
vector<string> aheadercolumn(headerrow, headerrow + 1);
|
||||||
aheadercolumn.insert(aheadercolumn.end(), headercolumn, headercolumn + columns - 1);
|
aheadercolumn.insert(aheadercolumn.end(), headercolumn, headercolumn + columns - 1);
|
||||||
|
|
||||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
tables::options aoptions;
|
tables::options aoptions;
|
||||||
@ -413,7 +413,7 @@ int main()
|
|||||||
aoptions.boolalpha = true;
|
aoptions.boolalpha = true;
|
||||||
// tables::options aoptions{.boolalpha = true};
|
// tables::options aoptions{.boolalpha = true};
|
||||||
|
|
||||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||||
{
|
{
|
||||||
aoptions.style = k;
|
aoptions.style = k;
|
||||||
|
|
||||||
@ -448,7 +448,7 @@ int main()
|
|||||||
|
|
||||||
tables::options aoptions;
|
tables::options aoptions;
|
||||||
|
|
||||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||||
{
|
{
|
||||||
aoptions.style = k;
|
aoptions.style = k;
|
||||||
|
|
||||||
@ -477,7 +477,7 @@ int main()
|
|||||||
|
|
||||||
tables::options aoptions;
|
tables::options aoptions;
|
||||||
|
|
||||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||||
{
|
{
|
||||||
aoptions.style = k;
|
aoptions.style = k;
|
||||||
|
|
||||||
@ -498,7 +498,7 @@ int main()
|
|||||||
|
|
||||||
tables::options aoptions;
|
tables::options aoptions;
|
||||||
|
|
||||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||||
{
|
{
|
||||||
aoptions.style = k;
|
aoptions.style = k;
|
||||||
|
|
||||||
@ -512,7 +512,7 @@ int main()
|
|||||||
aoptions.headerrow = true;
|
aoptions.headerrow = true;
|
||||||
// tables::options aoptions{.headerrow = true};
|
// tables::options aoptions{.headerrow = true};
|
||||||
|
|
||||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||||
{
|
{
|
||||||
aoptions.style = k;
|
aoptions.style = k;
|
||||||
|
|
||||||
@ -527,7 +527,7 @@ int main()
|
|||||||
aoptions.headerrow = true;
|
aoptions.headerrow = true;
|
||||||
// tables::options aoptions{.headerrow = true};
|
// tables::options aoptions{.headerrow = true};
|
||||||
|
|
||||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||||
{
|
{
|
||||||
aoptions.style = k;
|
aoptions.style = k;
|
||||||
|
|
||||||
@ -543,7 +543,7 @@ int main()
|
|||||||
aoptions.headerrow = true;
|
aoptions.headerrow = true;
|
||||||
// tables::options aoptions{.headerrow = true};
|
// tables::options aoptions{.headerrow = true};
|
||||||
|
|
||||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||||
{
|
{
|
||||||
aoptions.style = k;
|
aoptions.style = k;
|
||||||
|
|
||||||
@ -560,7 +560,7 @@ int main()
|
|||||||
aoptions.headerrow = true;
|
aoptions.headerrow = true;
|
||||||
// tables::options aoptions{.headerrow = true};
|
// tables::options aoptions{.headerrow = true};
|
||||||
|
|
||||||
for (unsigned int k = 0; k < size(tables::styles); ++k)
|
for (unsigned int k = 0; k < tables::size(tables::styles); ++k)
|
||||||
{
|
{
|
||||||
aoptions.style = k;
|
aoptions.style = k;
|
||||||
|
|
||||||
|
20
tables.hpp
20
tables.hpp
@ -45,6 +45,12 @@ namespace tables
|
|||||||
|
|
||||||
const options defaultoptions;
|
const options defaultoptions;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
auto size(const T &array)
|
||||||
|
{
|
||||||
|
return distance(begin(array), end(array));
|
||||||
|
}
|
||||||
|
|
||||||
// Number of columns needed to represent the string
|
// Number of columns needed to represent the string
|
||||||
// Adapted from: https://stackoverflow.com/a/31124065
|
// Adapted from: https://stackoverflow.com/a/31124065
|
||||||
int strcol(const char *str)
|
int strcol(const char *str)
|
||||||
@ -148,7 +154,7 @@ namespace tables
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
int table(const vector<vector<basic_string<T>>> &array, const options &aoptions)
|
int table(const vector<vector<basic_string<T>>> &array, const options &aoptions)
|
||||||
{
|
{
|
||||||
if (!size(array))
|
if (!tables::size(array))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
const bool headerrow = aoptions.headerrow;
|
const bool headerrow = aoptions.headerrow;
|
||||||
@ -159,7 +165,7 @@ namespace tables
|
|||||||
const char *const title = aoptions.title;
|
const char *const title = aoptions.title;
|
||||||
const unsigned int style = aoptions.style;
|
const unsigned int style = aoptions.style;
|
||||||
|
|
||||||
if (style >= size(styles))
|
if (style >= tables::size(styles))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
const size_t rows = array.size();
|
const size_t rows = array.size();
|
||||||
@ -322,17 +328,17 @@ namespace tables
|
|||||||
template <typename T1, typename T2>
|
template <typename T1, typename T2>
|
||||||
int array(const T1 &aarray, T2 headerrow[] = nullptr, T2 headercolumn[] = nullptr, const options &aoptions = defaultoptions)
|
int array(const T1 &aarray, T2 headerrow[] = nullptr, T2 headercolumn[] = nullptr, const options &aoptions = defaultoptions)
|
||||||
{
|
{
|
||||||
if (!size(aarray))
|
if (!tables::size(aarray))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
unsigned int j = 0;
|
unsigned int j = 0;
|
||||||
|
|
||||||
size_t rows = size(aarray);
|
size_t rows = tables::size(aarray);
|
||||||
size_t columns = size(aarray[0]);
|
size_t columns = tables::size(aarray[0]);
|
||||||
|
|
||||||
if (!all_of(begin(aarray), end(aarray), [columns](auto &x)
|
if (!all_of(begin(aarray), end(aarray), [columns](auto &x)
|
||||||
{ return size(x) == columns; }))
|
{ return tables::size(x) == columns; }))
|
||||||
{
|
{
|
||||||
cerr << "Error: The rows of the array must have the same number of columns.";
|
cerr << "Error: The rows of the array must have the same number of columns.";
|
||||||
return 1;
|
return 1;
|
||||||
@ -451,7 +457,7 @@ namespace tables
|
|||||||
const char *const aheaderrow[] = {"x", "y"};
|
const char *const aheaderrow[] = {"x", "y"};
|
||||||
// const char* const aheaderrow[] = {"", "x", "y"};
|
// const char* const aheaderrow[] = {"", "x", "y"};
|
||||||
|
|
||||||
const size_t length = size(aheaderrow);
|
const size_t length = tables::size(aheaderrow);
|
||||||
|
|
||||||
string *headerrow = new string[columns];
|
string *headerrow = new string[columns];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user