Matrix.hpp
1 #pragma once
2 
3 #include <opals/fwd.hpp>
4 
5 #include <cstddef>
6 #include <array>
7 
8 namespace opals {
9 
10  /**
11  \class Matrix
12  \tparam T element type
13  \tparam nRows_ number of rows
14  \tparam nCols_ number of columns
15 
16  \brief A template class for storing a two-dimensional array of constant size.
17 
18  Matrix fulfills almost all the requirements of an STL reversible container.
19  The complete implementation is exposed and hence, opals users may instantiate Matrix<T, nRows_, nCols_> with arbitrary template arguments.
20  The class inherits most of its functionality from std::array, with elements stored in row-major order.
21 
22  \author wk
23  \date 06.02.2011
24  */
25 
26  template< class T, std::size_t nRows_, std::size_t nCols_ >
27  class Matrix : public std::array<T, nRows_ * nCols_>
28  {
29  public:
30  /// swap
31  void swap(Matrix& other) { Matrix::array::swap(other); }
32 
33  /// \name element access
34  /// zero-based indexing
35  ///@{
36  T& operator()(size_t r, size_t c)
37  {
38  return (*this)[r * nCols_ + c];
39  }
40  const T& operator()(size_t r, size_t c) const
41  {
42  return (*this)[r * nCols_ + c];
43  }
44  ///@}
45 
46  /// \name size
47  ///@{
48  size_t nRows() const { return nRows_; }
49  size_t nCols() const { return nCols_; }
50  ///@}
51 
52  };
53 
54 }
Contains the public interface of OPALS.
Definition: AbsValueOrQuantile.hpp:8
void swap(Matrix &other)
swap
Definition: Matrix.hpp:31
A template class for storing a two-dimensional array of constant size.
Definition: fwd.hpp:17