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:
//1 This line sets the complex variable el equal to the value of entry (2,2) of the matrix. As with the subscripting operator, bounds checking is done only if the preprocessor symbol BOUNDS_CHECK is defined when the header file is read.
Using val() can generate smaller and faster code than the functionally equivalent line:
DComplex el = H(2,2);
because the subscripting operator for Hermitian matrices uses a helper class in order to maintain conjugate transpose symmetry within the matrix.
//2 This line sets entry (2,2) of the matrix equal to the complex number 3+2i. As before, bounds checking is done only if the preprocessor symbol BOUNDS_CHECK is defined when the header file is read. Also, as before, this can generate smaller and faster code than the equivalent:
H(2,2) = DComplex(3,2);