CopperSpice API
1.9.2
|
Template class which provides a dynamic or resizable array. More...
Classes | |
class | const_iterator |
The QVector::const_iterator class provides an STL style const iterator for QVector and QStack More... | |
class | iterator |
The QVector::iterator class provides an STL style iterator for QVector and QStack More... | |
Public Typedefs | |
using | allocator_type = typename std::vector< T >::allocator_type |
using | const_iterator = typename std::vector< T >::const_iterator |
using | const_pointer = typename std::vector< T >::const_pointer |
using | const_reference = typename std::vector< T >::const_reference |
using | const_reverse_iterator = typename std::vector< T >::const_reverse_iterator |
using | difference_type = typename std::vector< T >::difference_type |
using | iterator = typename std::vector< T >::iterator |
using | Java_Iterator = QVectorIterator< T > |
using | Java_MutableIterator = QMutableVectorIterator< T > |
using | pointer = typename std::vector< T >::pointer |
using | reference = typename std::vector< T >::reference |
using | reverse_iterator = typename std::vector< T >::reverse_iterator |
using | size_type = typename std::vector< T >::difference_type |
using | value_type = typename std::vector< T >::value_type |
Public Methods | |
QVector () = default | |
QVector (const QVector< T > &other) = default | |
template<class Input_Iterator > | |
QVector (Input_Iterator first, Input_Iterator last) | |
QVector (QVector< T > &&other) = default | |
QVector (size_type size) | |
QVector (size_type size, const T &value) | |
QVector (std::initializer_list< T > args) | |
~QVector () = default | |
void | append (const QVector< T > &other) |
void | append (const T &value) |
template<typename Iter > | |
void | append (Iter begin, Iter end) |
void | append (T &&value) |
const_reference | at (size_type pos) const |
reference | back () |
const_reference | back () const |
iterator | begin () |
const_iterator | begin () const |
size_type | capacity () const |
const_iterator | cbegin () const |
const_iterator | cend () const |
void | clear () |
const_iterator | constBegin () const |
const T * | constData () const |
const_iterator | constEnd () const |
const_reference | constFirst () const |
const_reference | constLast () const |
bool | contains (const T &value) const |
size_type | count () const |
size_type | count (const T &value) const |
const_reverse_iterator | crbegin () const |
const_reverse_iterator | crend () const |
T * | data () |
const T * | data () const |
bool | empty () const |
iterator | end () |
const_iterator | end () const |
bool | endsWith (const T &value) const |
iterator | erase (const_iterator begin, const_iterator end) |
iterator | erase (const_iterator pos) |
QVector< T > & | fill (const T &value, size_type size=-1) |
reference | first () |
const_reference | first () const |
reference | front () |
const_reference | front () const |
size_type | indexOf (const T &value, size_type from=0) const |
iterator | insert (iterator before, const T &value) |
iterator | insert (iterator before, size_type count, const T &value) |
template<typename Iter > | |
iterator | insert (iterator pos, Iter begin, Iter end) |
void | insert (size_type pos, const T &value) |
void | insert (size_type pos, size_type count, const T &value) |
bool | isEmpty () const |
reference | last () |
const_reference | last () const |
size_type | lastIndexOf (const T &value, size_type from=-1) const |
size_type | length () const |
QVector< T > | mid (size_type pos, size_type length=-1) const |
void | move (size_type from, size_type to) |
bool | operator!= (const QVector< T > &other) const |
QVector< T > | operator+ (const QVector< T > &other) const |
QVector< T > & | operator+= (const QVector< T > &other) |
QVector< T > & | operator+= (const T &value) |
QVector< T > & | operator<< (const QVector< T > &other) |
QVector< T > & | operator<< (const T &value) |
QVector< T > & | operator= (const QVector< T > &other) = default |
QVector< T > & | operator= (QVector< T > &&other) = default |
bool | operator== (const QVector< T > &other) const |
reference | operator[] (size_type i) |
const_reference | operator[] (size_type i) const |
void | pop_back () |
void | pop_front () |
void | prepend (const T &value) |
void | push_back (const T &value) |
void | push_back (T &&value) |
void | push_front (const T &value) |
void | push_front (T &&value) |
reverse_iterator | rbegin () |
const_reverse_iterator | rbegin () const |
void | remove (size_type pos) |
void | remove (size_type pos, size_type count) |
size_type | removeAll (const T &value) |
void | removeAt (size_type pos) |
void | removeFirst () |
void | removeLast () |
bool | removeOne (const T &value) |
reverse_iterator | rend () |
const_reverse_iterator | rend () const |
void | replace (size_type i, const T &value) |
void | reserve (size_type size) |
void | resize (size_type size) |
size_type | size () const |
void | squeeze () |
bool | startsWith (const T &value) const |
void | swap (QVector< T > &other) |
T | takeAt (size_type pos) |
T | takeFirst () |
T | takeLast () |
QList< T > | toList () const |
std::vector< T > | toStdVector () const |
T | value (size_type pos) const |
T | value (size_type pos, const T &defaultValue) const |
Static Public Methods | |
static QVector< T > | fromList (const QList< T > &list) |
static QVector< T > | fromStdVector (const std::vector< T > &vector) |
Related Functions | |
These are not member functions | |
bool | operator< (const QVector< T > &lhs, const QVector< T > &rhs) |
QDataStream & | operator<< (QDataStream &stream, const QVector< T > &vector) |
bool | operator<= (const QVector< T > &lhs, const QVector< T > &rhs) |
bool | operator> (const QVector< T > &lhs, const QVector< T > &rhs) |
bool | operator>= (const QVector< T > &lhs, const QVector< T > &rhs) |
QDataStream & | operator>> (QDataStream &stream, QVector< T > &vector) |
QVector is a template class which provides a dynamic or resizable array. This container stores elements in contiguous memory locations and provides fast index access.
For an overview and comparison of all containers, refer to the documentation for Container Classes. Refer to the section on Time Complexity for a discussion about which operations will be relatively faster or slower for a given container with a size of n.
A QVector can be created with an initial size. The following code constructs a QVector with 200 elements and each element will be default initialized. Refer to default constructed elements for additional information.
If you want to declare and initialize the new elements with a specific value, pass the value as the second argument to the constructor as shown below. The fill() method could also be called after the vector is created to assign a given value to every element.
QVector containers in C++ use 0 based indexes. To access the element at a particular index position, use operator[]. For non-const vectors, operator[] returns an lvalue reference to the element. If this operator appears on the left side of an assignment then the element in the container will be modified.
For read only access an alternative syntax is to use the at() method.
Another way to access the elements of a QVector is to call data(). This method returns a pointer to the first element in the vector. This pointer can be used to directly access and modify the elements stored in the vector. The pointer is also useful if you need to pass a QVector to a method which requires a C array.
If you want to find all occurrences of a particular value in a vector, use indexOf() or lastIndexOf(). The former searches forward starting from a given index position, the latter searches backward. Both return the index of the matching element if they found one, otherwise they return -1.
QVector provides basic methods to add, move, and remove elements: insert(), replace(), remove(), prepend(), append().
For large vectors methods like insert(), remove(), and prepend() may be slow because they require moving elements in the vector by one position in memory. If you want a container class that provides fast insertion/removal in the middle, use QList or QLinkedList instead. Refer to linear time for more information.
If you want to check whether a vector contains a particular value use the method contains(). If you want to find out how many times a particular value occurs in the vector use count(). Unlike C arrays QVector can be resized at any time by calling the method resize(). If the new size is larger than the old size QVector might need to reallocate the entire vector.
If you know the approximate number of elements the QVector will contain, you can call reserve(). This method preallocates a certain amount of memory which is more efficient than reallocating several times. You can also call capacity() to find out how much memory QVector actually allocated.
The QVector value type T should be Default Constructible and Copy Constructible to work with all methods of this class. Data types like QObject are not copy constructible and therefore should never be stored in a container. You can however use a pointer to a QObject or any subclass as the type T.
A few methods have additional requirements. For example, indexOf() and lastIndexOf() need the value type T to support operator==()
. If any other constraints exist, they will appear in the documentation for the given method.
QVector provides Java style iterators (QVectorIterator and QMutableVectorIterator) and STL style iterators (QVector::const_iterator and QVector::iterator). QVector is implemented so that direct index access is just as fast as using iterators.
In addition to QVector there is also QVarLengthArray which is a low-level class with a smaller API. It is optimized for speed. QVector does not support inserting, prepending, appending, or replacing with references to other elements in the vector.
QVector< T >::allocator_type |
Typedef for allocator used by the container.
QVector< T >::const_iterator |
Typedef for an STL style const iterator.
QVector< T >::const_pointer |
Typedef for const T *.
QVector< T >::const_reference |
Typedef for const T &.
QVector< T >::const_reverse_iterator |
Typedef for an STL style const reverse iterator.
QVector< T >::difference_type |
Typedef for integral type used to represent the distance between two elements.
QVector< T >::iterator |
Typedef for an STL style iterator.
QVector< T >::Java_Iterator |
Typedef for the java style const iterator.
QVector< T >::Java_MutableIterator |
Typedef for the java style mutable iterator.
QVector< T >::pointer |
Typedef for T *.
QVector< T >::reference |
Typedef for T &.
QVector< T >::reverse_iterator |
Typedef for an STL style reverse iterator.
QVector< T >::size_type |
Typedef for a signed integer of the appropriate size for your platform.
QVector< T >::value_type |
Typedef for T.
|
default |
Constructs an empty QVector.
|
inlineexplicit |
Constructs a QVector with an initial size of size elements. The elements are default initialized with a default-constructed value.
|
inline |
|
default |
Copy constructs a new QVector from other.
|
default |
Move constructs a new QVector from other.
|
inline |
Construct a QVector from the given args.
|
inline |
Construct a QVector containing the elements from first to last.
|
default |
Destroys the QVector.
|
inline |
Appends the elements of the other vector to this vector.
|
inline |
Copy appends value at the end of the vector.
This is the same as calling resize(size() + 1) and assigning value to the new last element in the vector.
This operation is relatively fast because QVector typically allocates more memory than necessary. This means the vector can grow without reallocating the entire vector each time.
|
inline |
Appends the elements in the range from begin to end to this QVector.
|
inline |
Move appends from value to this QVector.
|
inline |
Returns the element at index position pos in this QVector. The value for pos must be a valid index position in the QVector.
|
inline |
Returns a reference to the last element. Equivalent to calling last().
|
inline |
Returns a const reference to the last element. Equivalent to calling last().
|
inline |
Returns an STL style iterator pointing to the first element in the vector.
|
inline |
Returns a const STL style iterator pointing to the first element in the vector.
|
inline |
|
inline |
Returns a const STL style iterator positioned at the first element in the QVector.
|
inline |
Returns a const STL style iterator pointing to the imaginary element after the last element in the QVector.
|
inline |
Removes all the elements from this QVector.
|
inline |
Returns a const STL style iterator pointing to the first element in the QVector.
|
inline |
Returns a const pointer to the data which can be used to access the elements in the vector. The pointer remains valid as long as the vector is not reallocated.
This method is useful when you need to pass a vector to a method which accepts a C array.
|
inline |
Returns a const STL style iterator pointing to the imaginary element after the last element in the QVector.
|
inline |
|
inline |
bool QVector< T >::contains | ( | const T & | value | ) | const |
Returns true if the vector contains an occurrence of value, otherwise returns false. This method requires the type T to support operator==()
.
QVector< T >::size_type QVector< T >::count | ( | const T & | value | ) | const |
Returns the number of occurrences of value in the vector. This method requires the type T to support operator==()
.
|
inline |
Returns a const STL style reverse iterator pointing to the first element in the vector, in reverse order.
|
inline |
Returns a const STL style reverse iterator pointing to one past the last element in the vector, in reverse order.
|
inline |
Returns a pointer to the data stored in the vector. The pointer can be used to access and modify the elements in the vector.
The pointer remains valid as long as the vector is not reallocated. This method is mostly useful to pass a vector to a method which accepts a C array.
|
inline |
Returns a const pointer to the data stored in the QVector.
|
inline |
This method is equivalent to calling isEmpty(). It returns true if the vector is empty, otherwise it returns false.
|
inline |
Returns an STL style iterator pointing to the imaginary element after the last element in the vector.
|
inline |
Returns a const STL style iterator pointing to the imaginary element after the last element in the vector.
|
inline |
|
inline |
Removes all the elements from begin to end, not including the element pointed to by end. Returns an iterator to the element which end referred to, prior to calling this method.
|
inline |
QVector< T > & QVector< T >::fill | ( | const T & | value, |
size_type | size = -1 |
||
) |
Assigns value to all elements in the vector. If size is different from -1 the vector is first resized.
|
inline |
|
inline |
Returns a reference to the first element in the vector. This method assumes the vector is not empty.
|
inlinestatic |
Returns a QVector object with the data contained in list.
|
inlinestatic |
Returns a QVector object with the data contained in vector.
|
inline |
|
inline |
|
inline |
Returns the index position of the first occurrence of value in the vector, searching forward from index position from. Returns -1 if no element matched.
This method requires the type T to support operator==()
.
Inserts value in front of the element pointed to by the iterator before. Returns an iterator pointing at the inserted element.
|
inline |
Inserts count copies of value in front of the element pointed to by the iterator before. Returns an iterator pointing at the first of the inserted elements.
|
inline |
Inserts the elements in the range from begin to end to this vector at iterator position pos.
|
inline |
Inserts value at index position pos in the vector. If pos is 0 the value is prepended to the vector. If pos is equal to size(), the value is appended to the vector.
For large vectors this operation can be slow (linear time) because it requires moving all the elements past the current index. If you want a container class which provides a fast insert() method use QLinkedList instead.
|
inline |
Inserts count copies of value at index position pos in the vector.
|
inline |
|
inline |
|
inline |
Returns a const reference to the last element in the vector. This method assumes the vector is not empty.
|
inline |
Returns the index position of the last occurrence of the value in the vector, searching backward from index position from. If from is -1 the search starts at the last element. Returns -1 if no element matched.
This method requires the type T to support operator==()
.
|
inline |
Returns a vector whose elements are copied from this vector, starting at position pos. If length is -1 then all elements after pos are returned, otherwise the given length of elements is returned. If the length is greater than number of elements the value for length is ignored.
Moves the element at index position from to index position to. Provided for compatibility with QList.
|
inline |
Returns true if other is not equal to this vector, otherwise returns false. Two vectors are considered equal if they contain the same values in the same order.
This method requires the type T to support operator==()
.
|
inline |
Returns a vector that contains all the elements in this vector followed by all the elements in the other vector.
QVector< T > & QVector< T >::operator+= | ( | const QVector< T > & | other | ) |
Appends the elements of the other vector to this vector and returns a reference to this vector.
|
inline |
Appends value to the vector.
|
inline |
Appends other to the vector and returns a reference to the vector.
|
inline |
Appends value to the vector and returns a reference to this vector.
|
default |
Copy assigns from other and returns a reference to this object.
|
default |
Move assigns from other and returns a reference to this object.
This version takes an rvalue. Refer to references for a detailed description of rvalues and move semantics.
|
inline |
Returns true if other is equal to this vector, otherwise returns false. Two vectors are considered equal if they contain the same values in the same order.
This method requires the type T to support operator==()
.
|
inline |
Equivalent to calling at(i).
|
inline |
This method is equivalent to calling erase(end() - 1).
|
inline |
This method is equivalent to calling erase(begin()).
|
inline |
Inserts value at the beginning of the vector.
Equivalent to calling vector.insert(0, value).
For large vectors this operation can be slow (linear time), because it requires moving all the elements by one position. If you want a container class which provides a fast prepend() method use QList instead.
|
inline |
Equivalent to calling append(value).
|
inline |
Equivalent to calling append(value).
|
inline |
Equivalent to calling prepend(value).
|
inline |
Equivalent to calling prepend(value).
|
inline |
Returns an STL style reverse iterator pointing to the last element in the vector.
|
inline |
Returns a const STL style reverse iterator pointing to the last element in the vector.
|
inline |
Removes the element at index position pos.
For large vectors this operation can be slow (linear time), because it requires moving all the elements at indexes i and above by one position further in memory. If you want a container class which provides a fast remove() method use QLinkedList instead.
QVector< T >::size_type QVector< T >::removeAll | ( | const T & | value | ) |
Removes all elements which compare equal to value. Returns the number of elements removed, if any.
|
inline |
|
inline |
Removes the first element in the list. Calling this method is equivalent to calling removeAt(0). The list must not be empty. If the list can be empty, call isEmpty() before calling this method.
|
inline |
Removes the last element in the list. Calling this method is equivalent to calling removeAt(size() - 1). The list must not be empty. If the list can be empty, call isEmpty() before calling this method.
|
inline |
Removes the first occurrence of value in the list and returns true on success, otherwise returns false.
This method requires the type T to support operator==()
.
|
inline |
Returns an STL style reverse iterator pointing to one before the first element in the vector.
|
inline |
Returns a const STL style reverse iterator pointing to one before the first element in the vector.
|
inline |
Replaces the element at index position i with value. The value for i must be a valid index position in the vector, i >= 0 and i < size().
|
inline |
Attempts to allocate memory for at least size elements. If you know in advance how large the vector will be, you can call this method, and if you call resize() often you are likely to get better performance. If size is an underestimate, the worst that will happen is that the QVector will be a bit slower.
The sole purpose of this method is to provide a means of fine tuning QVector's memory usage. In general, you will rarely ever need to call this method. If you want to change the size of the vector, call resize().
|
inline |
Sets the size of the vector to size. If size is greater than the current size, elements are added to the end. The new elements are default initialized with a default-constructed value. If size is less than the current size, elements are removed from the end.
|
inline |
|
inline |
Releases any memory not required to store the elements in the vector.
|
inline |
|
inline |
Swaps vector other with this vector. This operation is very fast and never fails.
|
inline |
Removes the element at index position pos and returns it. The value for pos must be a valid index position in the list, pos >= 0 and pos < size().
If you do not use the return value removeAt() is more efficient.
|
inline |
Removes the first element in the list and returns it. This is the same as takeAt(0). This method assumes the list is not empty. To avoid failure, call isEmpty() before calling this method.
If you do not use the return value removeFirst() is more efficient.
|
inline |
Removes the last element in the list and returns it. This is the same as takeAt(size() - 1). This method assumes the list is not empty. To avoid failure, call isEmpty() before calling this method.
If you do not use the return value removeLast() is more efficient.
QList< T > QVector< T >::toList | ( | ) | const |
Returns a QList object with the data contained in this QVector.
|
inline |
Returns a std::vector object with the data contained in this QVector.
T QVector< T >::value | ( | size_type | pos | ) | const |
Returns the value at index position pos in the vector. If you are certain that pos is within bounds, use the method at() which is slightly faster. If the value for pos is out of bounds, a value initialized object of type T is returned. Refer to default constructed elements for additional information.
T QVector< T >::value | ( | size_type | pos, |
const T & | defaultValue | ||
) | const |
Returns the value at index position pos in the vector. If the index pos out of bounds then defaultValue is returned.
|
related |
Returns true if vector lhs is lexicographically less than rhs, otherwise returns false. This method requires the type T to support operator<()
.
|
related |
Writes the given vector to the stream. Returns a reference to the stream. This function requires the type T to support operator<<()
.
Refer to Serializing Data Types for additional information.
|
related |
Returns true if vector lhs is lexicographically less than or equal to rhs, otherwise returns false. This method requires the type T to support operator<()
.
|
related |
Returns true if vector lhs is lexicographically greater than rhs, otherwise returns false. This method requires the type T to support operator<()
.
|
related |
Returns true if vector lhs is lexicographically greater than or equal to rhs, otherwise returns false. This method requires the type T to support operator<()
.
|
related |
Reads from the stream into the given vector. Returns a reference to the stream. This function requires the type T to support operator>>()
.
Refer to Serializing Data Types for additional information.