Tools.h++ Manual

13-6 104011 Tandem Computers Incorporated
13
Each program line is detailed below.
1. This is where the template for
RWTValVector<T>
is defined.
2. A vector of doubles, 20 elements long and initialized to 0.0 is declared
and defined.
3. The first 10 elements of the vector are set to 1.0. Here,
RWValVector<double>::operator[](int)
has been used. This
operator always performs a bounds check on its argument.
4. The next 10 elements of the vector are set to 2.0. In this case
RWValVector<double>::operator()(int)
has been used. This
operator generally does not perform a bounds check.
Note – For all Tools.h++ classes,
operator[](int)
always performs a
bounds check on its argument.
Some classes also support
operator()(int)
. Bounds checking is generally
not performed for this operator unless you define
RWBOUNDS_CHECK
before
including the header file.
5. Member function
reshape(int)
changes the length of the vector.
Note – If a vector is lengthened using
reshape(int)
, then the values of the
new elements are undefined.
If a vector is lengthened using
resize(int)
, then the new values are
initialized to something sensible, generally zero or blanks, depending on the
vector type.
All Tools.h++ vectors work this way.
6. Finally, the last 10 elements are initialized to 3.0.
vec.reshape(30); // 5
for (i=21; i<30; i++) vec[i] = 3.0; // 6
return 0;
}
Code Example 13-1 (Continued)