Export (0) Print
Expand All

vector (STL/CLR)

Updated: December 2008

The template class describes an object that controls a varying-length sequence of elements that has random access. You use the container vector to manage a sequence of elements as a contiguous block of storage. The block is implemented as an array that grows on demand.

In the description below, GValue is the same as Value unless the latter is a ref type, in which case it is Value^.

template<typename Value>
    ref class vector
        :   public
        System::ICloneable,
        System::Collections::IEnumerable,
        System::Collections::ICollection,
        System::Collections::Generic::IEnumerable<GValue>,
        System::Collections::Generic::ICollection<GValue>,
        System::Collections::Generic::IList<GValue>,
        Microsoft::VisualC::StlClr::IVector<GValue>
    { ..... };

Value

The type of an element in the controlled sequence.

Type Definition

Description

vector::const_iterator (STL/CLR)

The type of a constant iterator for the controlled sequence.

vector::const_reference (STL/CLR)

The type of a constant reference to an element.

vector::const_reverse_iterator (STL/CLR)

The type of a constant reverse iterator for the controlled sequence.

vector::difference_type (STL/CLR)

The type of a signed distance between two elements.

vector::generic_container (STL/CLR)

The type of the generic interface for the container.

vector::generic_iterator (STL/CLR)

The type of an iterator for the generic interface for the container.

vector::generic_reverse_iterator (STL/CLR)

The type of a reverse iterator for the generic interface for the container.

vector::generic_value (STL/CLR)

The type of an element for the generic interface for the container.

vector::iterator (STL/CLR)

The type of an iterator for the controlled sequence.

vector::reference (STL/CLR)

The type of a reference to an element.

vector::reverse_iterator (STL/CLR)

The type of a reverse iterator for the controlled sequence.

vector::size_type (STL/CLR)

The type of a signed distance between two elements.

vector::value_type (STL/CLR)

The type of an element.

Member Function

Description

vector::assign (STL/CLR)

Replaces all elements.

vector::at (STL/CLR)

Accesses an element at a specified position.

vector::back (STL/CLR)

Accesses the last element.

vector::begin (STL/CLR)

Designates the beginning of the controlled sequence.

vector::capacity (STL/CLR)

Reports the size of allocated storage for the container.

vector::clear (STL/CLR)

Removes all elements.

vector::empty (STL/CLR)

Tests whether no elements are present.

vector::end (STL/CLR)

Designates the end of the controlled sequence.

vector::erase (STL/CLR)

Removes elements at specified positions.

vector::front (STL/CLR)

Accesses the first element.

vector::insert (STL/CLR)

Adds elements at a specified position.

vector::pop_back (STL/CLR)

Removes the last element.

vector::push_back (STL/CLR)

Adds a new last element.

vector::rbegin (STL/CLR)

Designates the beginning of the reversed controlled sequence.

vector::rend (STL/CLR)

Designates the end of the reversed controlled sequence.

vector::reserve (STL/CLR)

Ensures a minimum growth capacity for the container.

vector::resize (STL/CLR)

Changes the number of elements.

vector::size (STL/CLR)

Counts the number of elements.

vector::swap (STL/CLR)

Swaps the contents of two containers.

vector::to_array (STL/CLR)

Copies the controlled sequence to a new array.

vector::vector (STL/CLR)

Constructs a container object.

Property

Description

vector::back_item (STL/CLR)

Accesses the last element.

vector::front_item (STL/CLR)

Accesses the first element.

Operator

Description

vector::operator= (STL/CLR)

Replaces the controlled sequence.

vector::operator[] (STL/CLR)

Accesses an element at a specified position.

operator!= (vector) (STL/CLR)

Determines if a vector object is not equal to another vector object.

operator< (vector) (STL/CLR)

Determines if a vector object is less than another vector object.

operator<= (vector) (STL/CLR)

Determines if a vector object is less than or equal to another vector object.

operator== (vector) (STL/CLR)

Determines if a vector object is equal to another vector object.

operator> (vector) (STL/CLR)

Determines if a vector object is greater than another vector object.

operator>= (vector) (STL/CLR)

Determines if a vector object is greater than or equal to another vector object.

Interface

Description

ICloneable

Duplicate an object.

IEnumerable

Sequence through elements.

ICollection

Maintain group of elements.

IEnumerable<T>

Sequence through typed elements.

ICollection<T>

Maintain group of typed elements.

IList<T>

Maintain ordered group of typed elements.

IVector<Value>

Maintain generic container.

The object allocates and frees storage for the sequence it controls through a stored array of Value elements, which grows on demand. Growth occurs in such a way that the cost of appending a new element is amortized constant time. In other words, the cost of adding elements at the end does not increase, on average, as the length of the controlled sequence gets larger. Thus, a vector is a good candidate for the underlying container for template class stack (STL/CLR).

A vector supports random-access iterators, which means you can refer to an element directly given its numerical position, counting from zero for the first (front) element, to vector::size (STL/CLR)() - 1 for the last (back) element. It also means that a vector is a good candidate for the underlying container for template class priority_queue (STL/CLR).

A vector iterator stores a handle to its associated vector object, along with the bias of the element it designates. You can use iterators only with their associated container objects. The bias of a vector element is the same as its position.

Inserting or erasing elements can change the element value stored at a given position, so the value designated by an iterator can also change. (The container may have to copy elements up or down to create a hole before an insert or to fill a hole after an erase.) Nevertheless, a vector iterator remains valid so long as its bias is in the range [0, vector::size (STL/CLR)()]. Moreover, a valid iterator remains dereferencable -- you can use it to access or alter the element value it designates -- so long as its bias is not equal to size().

Erasing or removing an element calls the destructor for its stored value. Destroying the container erases all elements. Thus, a container whose element type is a ref class ensures that no elements outlive the container. Note, however, that a container of handles does not destroy its elements.

Header: <cliext/vector>

Namespace: cliext

Date

History

Reason

December 2008

Added link to parent.

Customer feedback.

Community Additions

ADD
Show:
© 2014 Microsoft