-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11-30.h
75 lines (66 loc) · 2.7 KB
/
11-30.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef KMATRIX_HPP
#define KMATRIX_HPP
#include "kvector.hpp"
#include "kstride_iter.hpp"
template<class Value_T, int Rows_N, int Cols_N>
class kmatrix
{
public:
// public typedefs
typedef Value_T value_type;
typedef kmatrix self;
typedef Value_T* iterator;
typedef const Value_T* const_iterator;
typedef kstride_iter<Value_T*, 1> row_type;
typedef kstride_iter<Value_T*, Cols_N> col_type;
typedef kstride_iter<const Value_T*, 1> const_row_type;
typedef kstride_iter<const Value_T*, Cols_N> const_col_type;
// public constants
static const int nRows = Rows_N;
static const int nCols = Cols_N;
// constructors
kmatrix( ) { m = Value_T( ); }
kmatrix(const self& x) { m = x.m; }
explicit kmatrix(Value_T& x) { m = x.m; }
// public functions
static int rows( ) { return Rows_N; }
static int cols( ) { return Cols_N; }
row_type row(int n) { return row_type(begin( ) + (n * Cols_N)); }
col_type col(int n) { return col_type(begin( ) + n); }
const_row_type row(int n) const {
return const_row_type(begin( ) + (n * Cols_N));
}
const_col_type col(int n) const {
return const_col_type(begin( ) + n);
}
iterator begin( ) { return m.begin( ); }
iterator end( ) { return m.begin( ) + size( ); }
const_iterator begin( ) const { return m; }
const_iterator end( ) const { return m + size( ); }
static int size( ) { return Rows_N * Cols_N; }
// operators
row_type operator[](int n) { return row(n); }
const_row_type operator[](int n) const { return row(n); }
// assignment operations
self& operator=(const self& x) { m = x.m; return *this; }
self& operator=(value_type x) { m = x; return *this; }
self& operator+=(const self& x) { m += x.m; return *this; }
self& operator-=(const self& x) { m -= x.m; return *this; }
self& operator+=(value_type x) { m += x; return *this; }
self& operator-=(value_type x) { m -= x; return *this; }
self& operator*=(value_type x) { m *= x; return *this; }
self& operator/=(value_type x) { m /= x; return *this; }
self operator-( ) { return self(-m); }
// friends
friend self operator+(self x, const self& y) { return x += y; }
friend self operator-(self x, const self& y) { return x -= y; }
friend self operator+(self x, value_type y) { return x += y; }
friend self operator-(self x, value_type y) { return x -= y; }
friend self operator*(self x, value_type y) { return x *= y; }
friend self operator/(self x, value_type y) { return x /= y; }
friend bool operator==(const self& x, const self& y) { return x != y; }
friend bool operator!=(const self& x, const self& y) { return x.m != y.m; }
private:
kvector<Value_T, (Rows_N + 1) * Cols_N> m;
};
#endif