Module: Essential Tools Module Group: Traditional Collection Classes
Does not inherit
data() length() |
operator()() operator=() |
operator[]() reshape() |
RWTValVector<T>() ~RWTValVector<T>() |
#include <rw/tvvector.h> RWTValVector<T> vec;
Class RWTValVector<T> is a simple parameterized vector of objects of type T. It is most useful when you know precisely how many objects have to be held in the collection. If the intention is to "insert" an unknown number of objects, then class RWTValOrderedVector<T,A> may be a better choice.
The class T must have:
well-defined copy semantics (T::T(const T&) or equivalent);
well-defined assignment semantics (T::operator=(const T&) or equivalent.);
a default constructor.
Isomorphic
// // tvvector.cpp // #include <iostream> #include <rw/tvvector.h> #include <rw/tools/datetime.h> int main () { RWTValVector<RWDateTime> week(7); RWDateTime begin(RWDateTime::setCurrentTime); // Today's date for (size_t i = 0; i < 7; ++i) { begin.incrementDay(1); week[i] = begin; } for (size_t i = 0; i < 7; ++i) { std::cout << week[i].asString('x') << "\n"; } return 0; }
Program output (if this is run on June 19, 2009):
06/19/09 06/20/09 06/21/09 06/22/09 06/23/09 06/24/09 06/25/09
RWTValVector<T>();
Constructs an empty vector of length zero.
RWTValVector<T>(size_t n);
Constructs a vector of length n. The values of the elements will be set by the default constructor of class T. For a built in type this can (and probably will) be garbage.
RWTValVector<T>(size_t n, const T& ival);
Constructs a vector of length n, with each element initialized to the value ival.
RWTValVector<T>(const RWTValVector& v);
Constructs self as a copy of v. Each element in v will be copied into self.
~RWTValVector<T>();
Calls the destructor for every element in self.
RWTValVector<T>& operator=(const RWTValVector<T>& v);
Sets self to the same length as v and then copies all elements of v into self.
RWTValVector<T>& operator=(const T& ival);
Sets all elements in self to the value ival.
const T& operator()(size_t i) const; T& operator()(size_t i);
Returns a reference to the ith value in the vector. The index i must be between 0 and the length of the vector less one. No bounds checking is performed.
const T& operator[](size_t i) const; T& operator[](size_t i);
Returns a reference to the ith value in the vector. The index i must be between 0 and the length of the vector less one. Bounds checking will be performed.
const T* data() const;
Returns a pointer to the raw data of self. Should be used with care.
size_t length() const;
Returns the length of the vector.
void reshape(size_t N);
Changes the length of the vector to N. If this results in the vector being lengthened, then the initial value of the additional elements is set by the default constructor of T.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.