-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix.h
executable file
·45 lines (36 loc) · 979 Bytes
/
matrix.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
#ifndef MATRIX_H
#define MATRIX_H
#include <vector>
#include <initializer_list>
using namespace std;
template <typename Object>
class matrix
{
public:
matrix( int rows, int cols ) : array( rows )
{
for( auto & thisRow : array )
thisRow.resize( cols );
}
matrix( initializer_list<vector<Object>> lst ) : array( lst.size( ) )
{
int i = 0;
for( auto & v : lst )
array[ i++ ] = std::move( v );
}
matrix( const vector<vector<Object>> & v ) : array{ v }
{ }
matrix( vector<vector<Object>> && v ) : array{ std::move( v ) }
{ }
const vector<Object> & operator[]( int row ) const
{ return array[ row ]; }
vector<Object> & operator[]( int row )
{ return array[ row ]; }
int numrows( ) const
{ return array.size( ); }
int numcols( ) const
{ return numrows( ) ? array[ 0 ].size( ) : 0; }
private:
vector<vector<Object>> array;
};
#endif