@@ -45,45 +45,46 @@ template <class T> class RectArray {
4545 // / @name Lifecycle
4646 // @{
4747 RectArray () : m_minrow(1 ), m_maxrow(0 ), m_mincol(1 ), m_maxcol(0 ), m_storage() {}
48- RectArray (unsigned int nrows, unsigned int ncols);
49- RectArray (int minr, int maxr, int minc, int maxc)
50- : m_minrow(minr), m_maxrow(maxr), m_mincol(minc), m_maxcol(maxc),
51- m_storage ((maxr >= minr && maxc >= minc) ? (maxr - minr + 1 ) * (maxc - minc + 1 ) : 0)
48+ RectArray (const size_t nrows, const size_t ncols) : RectArray(1 , nrows, 1 , ncols) {}
49+ RectArray (const int minrow, const int maxrow, const int mincol, const int maxcol)
50+ : m_minrow(minrow), m_maxrow(maxrow), m_mincol(mincol), m_maxcol(maxcol),
51+ m_storage ((maxrow >= minrow && maxcol >= mincol)
52+ ? (maxrow - minrow + 1 ) * (maxcol - mincol + 1 )
53+ : 0)
5254 {
5355 }
5456 RectArray (const RectArray &) = default;
5557 RectArray (RectArray &&) noexcept = default;
56-
57- virtual ~RectArray () = default ;
58+ ~RectArray () = default ;
5859
5960 RectArray &operator =(const RectArray &) = default ;
6061 RectArray &operator =(RectArray &&) noexcept = default ;
6162 // @}
6263
64+ // / @name Range checking functions; returns true only if valid index/size
65+ // @{
6366 // / check array for same row and column boundaries
6467 bool CheckBounds (const RectArray<T> &m) const
6568 {
6669 return (m_minrow == m.m_minrow && m_maxrow == m.m_maxrow && m_mincol == m.m_mincol &&
6770 m_maxcol == m.m_maxcol );
6871 }
69- // / @name Range checking functions; returns true only if valid index/size
70- // @{
7172 // / check for correct row index
72- bool CheckRow (int row) const { return (m_minrow <= row && row <= m_maxrow); }
73+ bool CheckRow (const int row) const { return (m_minrow <= row && row <= m_maxrow); }
7374 // / check row vector for correct column boundaries
74- template <class Vector > bool CheckRow (const Vector &v) const
75+ template <class V > bool CheckRow (const V &v) const
7576 {
76- return ( v.front_index () == m_mincol && v.back_index () == m_maxcol) ;
77+ return v.front_index () == m_mincol && v.back_index () == m_maxcol;
7778 }
7879 // / check for correct column index
79- bool CheckColumn (int col) const { return (m_mincol <= col && col <= m_maxcol); }
80+ bool CheckColumn (const int col) const { return (m_mincol <= col && col <= m_maxcol); }
8081 // / check column vector for correct row boundaries
81- template <class Vector > bool CheckColumn (const Vector &v) const
82+ template <class V > bool CheckColumn (const V &v) const
8283 {
8384 return (v.front_index () == m_minrow && v.back_index () == m_maxrow);
8485 }
8586 // / check row and column indices
86- bool Check (int row, int col) const { return CheckRow (row) && CheckColumn (col); }
87+ bool Check (const int row, const int col) const { return CheckRow (row) && CheckColumn (col); }
8788
8889 // @}
8990 // / @name General data access
@@ -131,7 +132,7 @@ template <class T> class RectArray {
131132 return ;
132133 }
133134
134- auto stride = row_stride ();
135+ const auto stride = row_stride ();
135136 const size_t ai = index (i, m_mincol);
136137 const size_t aj = index (j, m_mincol);
137138 for (size_t k = 0 ; k < stride; ++k) {
@@ -145,15 +146,6 @@ template <class T> class RectArray {
145146 // @}
146147};
147148
148- // ------------------------------------------------------------------------
149- // RectArray<T>: Constructors, destructor, constructive operators
150- // ------------------------------------------------------------------------
151-
152- template <class T >
153- RectArray<T>::RectArray(unsigned int rows, unsigned int cols) : RectArray(1 , rows, 1 , cols)
154- {
155- }
156-
157149// ------------------------------------------------------------------------
158150// RectArray<T>: Row and column rotation
159151// ------------------------------------------------------------------------
@@ -163,12 +155,9 @@ template <class T> void RectArray<T>::RotateUp(int lo, int hi)
163155 if (lo < m_minrow || hi < lo || m_maxrow < hi) {
164156 throw std::out_of_range (" Index out of range in RectArray" );
165157 }
166-
167- auto stride = row_stride ();
168-
169- size_t first = index (lo, m_mincol);
170- size_t last = index (hi + 1 , m_mincol);
171-
158+ const auto stride = row_stride ();
159+ const size_t first = index (lo, m_mincol);
160+ const size_t last = index (hi + 1 , m_mincol);
172161 std::rotate (m_storage.begin () + first, m_storage.begin () + first + stride,
173162 m_storage.begin () + last);
174163}
@@ -178,12 +167,9 @@ template <class T> void RectArray<T>::RotateDown(int lo, int hi)
178167 if (lo < m_minrow || hi < lo || m_maxrow < hi) {
179168 throw std::out_of_range (" Index out of range in RectArray" );
180169 }
181-
182- auto stride = row_stride ();
183-
184- size_t first = index (lo, m_mincol);
185- size_t last = index (hi + 1 , m_mincol);
186-
170+ const auto stride = row_stride ();
171+ const size_t first = index (lo, m_mincol);
172+ const size_t last = index (hi + 1 , m_mincol);
187173 std::rotate (m_storage.begin () + first, m_storage.begin () + last - stride,
188174 m_storage.begin () + last);
189175}
@@ -200,7 +186,7 @@ template <class T> template <class Vector> void RectArray<T>::GetRow(int row, Ve
200186 if (!CheckRow (v)) {
201187 throw DimensionException ();
202188 }
203- size_t base = index (row, m_mincol);
189+ const size_t base = index (row, m_mincol);
204190 for (int c = m_mincol; c <= m_maxcol; ++c) {
205191 v[c] = m_storage[base + (c - m_mincol)];
206192 }
0 commit comments