linalg::mat<T,M,N> defines a fixed-size matrix containing exactly M rows and N columns of type T, in column-major order.
This data structure is supported by a set of algebraic and component-wise functions, as well as a set of standard reductions.
mat<T,M,N>:
- is DefaultConstructible:
- is constructible from N columns of type vec<T,M>:
float2x2 m {{1,2},{3,4}};
- is constructible from linalg::identity:
float3x3 m = linalg::identity;
- is CopyConstructible and CopyAssignable:
float2x2 m {{1,2},{3,4}};
float2x2 n {m};
float2x2 p;
p = n;
- is EqualityComparable and LessThanComparable:
if(m == n) cout << "m and n contain equal elements in the same positions" <<
endl; if(m < n) cout << "m precedes n lexicographically when compared in
column-major order" << endl;
- is explicitly constructible from a single element of type T:
- is explicitly constructible from a mat<U,M,N> of some other type U:
float2x2 m {int2x2{{5,6},{7,8}}};
- supports indexing into columns:
float2x3 m {{1,2},{3,4},{5,6}};
float2 c = m[0];
m[1] = {7,8};
- supports retrieval (but not assignment) of rows:
float2x3 m {{1,2},{3,4},{5,6}};
float3 r = m.row(1);
- supports unary operators +, -, ! and ~ in component-wise fashion:
float2x2 m {{1,2},{3,4}};
float2x2 n = -m;
- supports binary operators +, -, *, /, %, |, &, ^, << and >> in component-wise fashion:
float2x2 a {{0,0},{2,2}};
float2x2 b {{1,2},{1,2}};
float2x2 c = a + b;
- supports binary operators with a scalar on the left or the right:
auto m = 2 * float2x2{{1,2},{3,4}};
- supports operators +=, -=, *=, /=, %=, |=, &=, ^=, <<= and >>= with matrices or scalars on the right:
float2x2 v {{5,4},{3,2}};
v *= 3;
- supports operations on mixed element types:
- supports range-based for over columns
- has a flat memory layout