val() and set()
Generally, you can use the familiar subscripting operator operator()(int,int) to access or set any element. The syntax is natural and intuitive. However, using this simple approach may not always be optimal, since, as we've seen, some matrix types require the use of a helper class for subscripting. This is because the subscripting operator can be used as either an lvalue or an rvalue, and hence must work when both examining and setting an element. The use of this helper class may cause your code to be slightly larger and slower than necessary.
To avoid these problems, two additional member functions are provided for element access: val() and set(). Both are used in the following example:
#include <rw/lapack/hbndmat.h> // Complex Hermitian banded
int main()
{
RWHermBandMat<DComplex> H(5,5,2);
DComplex el = H.val(2,2); // 1
H.set(2,2,DComplex(3,2)); // 2
return 0;
}
Let's consider each commented line: