|
Prev | Next |
| Name | Documentation |
std::vector | Section 16.3 of The C++ Programming Language |
std::valarray | Section 22.4 of The C++ Programming Language |
CppAD::vector | The CppAD::vector Template Class |
SimpleVector<Scalar>
The routine CheckSimpleVector
can be used to check
that a class is a simple vector class with a specified element type.
SimpleVector<Scalar> x;
creates an empty vector x (x.size() is zero)
that can later contain elements of the specified type
(see resize
below).
size_t,
SimpleVector<Scalar> x(n)
creates a vector x with n elements
each of the specified type.
SimpleVector<Scalar> object,
SimpleVector<Scalar> y(x)
creates a vector with the same type and number of elements
as x.
The Scalar assignment operator ( = )
is used to set each element of y
equal to the corresponding element of x.
This is a `deep copy' in that the values of the elements
of x and y can be set independently after the copy.
The argument x is passed by reference
and may be const.
SimpleVector<Scalar> objects,
y = x
uses the Scalar assignment operator ( = )
to set each element of y equal to
the corresponding element of x.
This is a `deep assignment' in that the values of the elements
of x and y can be set independently after the assignment.
The vectors x and y must have
the same number of elements.
The argument x is passed by reference
and may be const.
The type returned by this assignment is unspecified; for example,
it might be void in which case the syntax
z = y = x
would not be valid.
SimpleVector<Scalar> object
and n has type size_t,
n = x.size()
sets n to the number of elements in the vector x.
The object x may be const.
SimpleVector<Scalar> object
and n has type size_t,
x.resize(n)
changes the number of elements contained in the vector x
to be n.
The value of the elements of x
are not specified after this operation; i.e.,
any values previously stored in x are lost.
(The object x can not be const.)
Vector::value_type
is the type of the elements corresponding to the vector class; i.e.,
SimpleVector<Scalar>::value_type
is equal to Scalar.
SimpleVector<Scalar> object
and i has type size_t,
x[i]
returns an object of an unspecified type,
referred to here as elementType.
static_cast<Scalar>(x[i])
is used implicitly when x[i] is used in an expression
with values of type Scalar.
For this type of usage, the object x may be const.
x[i] = y
assigns the i-th element of x to have value y.
For this type of usage, the object x can not be const.
The type returned by this assignment is unspecified; for example,
it might be void in which case the syntax
z = x[i] = y
would not be valid.
Vector<double> x(2);
x[2] = 1.;
Create and run a program that executes the code segment
above where Vector is each of the following cases:
std::vector,
CppAD::vector.
Do this both where the compiler option
-DNDEBUG is and is not present on the compilation command line.
Vector<int> x(2);
Vector<int> y(1);
x[0] = 0;
x[1] = 1;
y = x;
Create and run a program that executes the code segment
above where Vector is each of the following cases:
std::valarray,
CppAD::vector.
Do this both where the compiler option
-DNDEBUG is and is not present on the compilation command line.