Utilities
-
template<typename T>
void divide(T x, T y, T &q, T &r) Return q = x/y and r = xy assuming x >= 0 && y >= 0.
- Parameters:
x – The dividend.
y – The divisor.
q – The quotient.
r – The remainder.
-
template<typename T>
class array_1d - #include <array_1d.hpp>
Adaptor class which can capture a container, initializer_list, row, or row_view with elements convertible to a specified type.
This class is used to capture a variety of acceptable argument types without relying on template parameters. For example:
void foo(const array_1d<int>&); // An initializer_list<int> (sort of...actually narrowing conversions are allowed): foo({1, 4, 4l, 3u}); // A linear container: std::vector<long> v{1, 5, 2}; foo(v); // A non-linear container: std::list<int> l{1, 6, 2, 0}; foo(l); // A row (1-d tensor): row<int> r{3}; r[0] = 0; r[1] = 4; r[2] = 2; foo(r); // A row_view: row_view<int> rv({v.size()}, v.data()); foo(rv);
- Template Parameters:
T – Elements of the supplied container, initializer list, etc. must be convertible to this type.
-
template<typename T>
class array_2d - #include <array_2d.hpp>
Adaptor class which can capture a 2-d data structure: a container of containers, matrix or matrix_view, nested initializer list, etc.
which have elements convertible to a specified type.
This class is used to capture a variety of acceptable argument types without relying on template parameters. For example:
void foo(const array_2d<int>&); // An initializer_list<initializer_list<int>> (sort of...actually narrowing conversions are allowed): foo({{1, 4}, {4l, 3u}}); // A container of containers: std::vector<std::list<long>> vv = {{1, 5}, {2, 1}}; foo(vv); // An initializer list of containers: std::vector<int> v1{1, 6}; std::vector<int> v2{2, 0}; foo({v1, v2}); // A matrix (2-d tensor): matrix<int> m = {{3, 4}, {0, 2}}; foo(m); // A matrix_view: std::vector<int> v{6, 3, 0, 1}; matrix_view<int> mv({2, 2}, v.data(), ROW_MAJOR); // view v as a 2-d structure: {{6, 3}, {0, 1}} foo(mv);
- Template Parameters:
T – Elements of the supplied container, initializer list, etc. must be convertible to this type.