Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
A matrix is a two-dimensional container (that is a container in which two values are needed to retrieve an element). For one-dimensional containers, go to the container page.
There exists no std::matrix (yet).
Possibilities are:
These possibilities are described below in more detail.
A std::vector can contain a collection of std::vectors. If all std::vectors in this collection are of the same size, one has a matrix.
When using std::vector<std::vector<int> > for a two-dimensional matrix, the choice between x-y-ordering or y-x-ordering must be made. The run-time speed difference does not reside in individual element read/write, but when obtaining a row or collumn: in a y-x-ordered std::vector<std::vector<int> > an individual row can be obtained, in an x-y-ordered std::vector<std::vector<int> > an individual collumn can be obtained.
Below is an example of a y-x-ordered std::vector<std::vector<int> >.
#include <cassert> |
Note that some of these code snippets also work on other containers.
The boost::multi_array (part of the Boost library) is not only support a two-dimensional matrix, but to many more dimensions.
When using C++ Builder 6.0, this does not compile (it results in the compile error borland.hpp: Only member functions may be 'const' or 'volatile').
The boost::numeric::ublas::matrix (part of the Boost library) support a two-dimensional matrix.
When using C++ Builder 6.0, this does not compile (it results in the compile error Your compiler and/or configuration is unsupported by this verions of uBLAS).
The blitz::Array (part of the Blitz++ library) is not only support a two-dimensional matrix, but to many more dimensions.
When using C++ Builder 6.0, this does not compile (it results in the compile error bzconfig.h: Unknown compiler).
Techsoft's matrix supports a x-y-ordered two-dimensional matrix.
#include <cassert> |
The Flood::Matrix (from the Flood library) supports a x-y-ordered two-dimensional matrix.
#include <cassert> |
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.