out of bound check for multidimensional arrays
<p>I am reading a book on Safe C++. Here author mentioned that how to avoid out of bound array reading. Here it is mentioned how we can avoid out of bound array reading for multi dimension arrays. Here author used operator() function as shown in following link instead of operator[] and gave following explanation.</p>

<p><a href="https://github.com/vladimir-kushnir/SafeCPlusPlus/blob/master/scpp_matrix.hpp" rel="nofollow">https://github.com/vladimir-kushnir/SafeCPlusPlus/blob/master/scpp_matrix.hpp</a></p>

<p>Note here To access multidimensional array, we either need to use multiple [] operators, such as matrix[i][j], or a single () operator, such as matrix(i,j).</p>

<p>The first approach can be achieved if we had the [] operator return a T* pointer to the zeroth elemenent of i-th row. However, this denies us the diagnosis of a column index out of bounds, which defeats the purpose of catching bugs at runtime. We could, ofcourse, create some template class that would incldue a smart reference to a row, return an instance of using the first operator([i]), and then use the bounds check in the second operator (j]).</p>

<p>My question what does author mean by "<strong>create some template class that would incldue a smart reference to a row, return an instance of using the first operator([i]), and then use the bounds check in the second operator (j])."</strong> ? Request to provide sample code how we can implement above logic in C++?</p>

<p>Thanks for your time and help.</p>
