C++ Simple matrix for the rest of us

Why yet another Matrix?

Here is why I did make it.

In the standard C++ community 2d arrays are the source of endless ongoing debate. Especially the large ones created on the heap.  While at the same time, approx 90% of use cases, in standard programs, do require, a plain old 2d array

But, It is a bit dangerous to let your team use this “naked”. It is not that comfortable if you use them regularly and it is dangerous since the stack space can deplete very fast.

As visible in the code behind this API, standard C++ is giving us quite a few mechanisms and features to encapsulate the rules of using such simple native matrices. Making it

Fast Safe and Comfortable

Actual usage might be a bit unusual because instances are not necessary. Just the types. Example

To use the test function declared above, we pass our matrix as a type and the rest of the arguments as value:

This is a very fast solution

Above means, there are no copy or move mechanisms being used whatsoever,  No complex, computation-intensive, matrix copying or swapping. The matrix simply stays in one place, where it was first created. Much like std::array conceptually works.

If one needs, to pass instances of this matrix in and out of function, as values, this is perfectly unnecessary but perfectly doable:

And the usage of the above function follows:

We receive the argument as value,   we return the matrix as value. It totally does not matter. There is no instance-bound data inside, Compiler has no job to do. Copy/move elision is not applicable. There is nothing to copy or move. No instances are necessary, get used to it :)

There are more usage samples,  all in the testing code provided.

The ‘your_print_function’ from above (same as dbj::console::print) is this

To the next page