Returns a constant reverse iterator which points to the reverse end of the vector. Returns a constant reverse iterator which points to the reverser beginning of the container. Returns a constant random access iterator which points to the beginning of the vector.ĭestroys the vector by removing all elements from the vector and sets size of vector to zero. Returns the size of allocate storage, expressed in terms of elements. Return a random access iterator pointing to the first element of the vector. Returns a reference to the last element of the vector. Returns reference to the element present at location n in the vector. Vector::vector initializer list constructorĬonstructs a container from initializer list.ĭestroys container by deallocating container memory.Īssign new values to the vector elements by replacing old ones. Constructors Sr.No.Ĭonstructs an empty container, with zero elements.Ĭonstructs a container with n elements and assignd val to each element.Ĭonstructs a container with as many elements in range of first to last.Ĭonstructs a container with copy of each elements present in existing container x.Ĭonstructs the container with the contents of other using move semantics. Sr.No.Ī random access iterator to const value_typeīelow is list of all methods from header. T may be substituted by any other data type including user-defined type.īy default, the allocator class template is used, which defines the simplest memory allocation model and is value-independent.įollowing member types can be used as parameters or return type by member functions. Definitionīelow is definition of std::vector from header file But behavior of calling front() or back() is undefined. In that case vector.begin() and vector.end() points to same location. Therefore, compared to array, vector consumes more memory in exchange for the ability to manage storage and grow dynamically in an efficient way.
![std lib vector code std lib vector code](https://linuxhint.com/wp-content/uploads/2021/07/image1-51.png)
![std lib vector code std lib vector code](https://d2vlcm61l7u1fs.cloudfront.net/media/a4a/a4ac1513-91ed-4d95-a12e-c624f5cb277f/phpfAwyvi.png)
To support shrink and expand functionality at runtime, vector container may allocate some extra storage to accommodate for possible growth thus container have actual capacity greater than the size. The storage of the vector is handled automatically. Unlike array, vector can shrink or expand as needed at run time. Vector stores elements in contiguous memory locations and enables direct access to any element using subscript operator. Sequence containers store elements strictly in linear sequence. Container is a objects that hold data of same type. Vectors are sequence container that can change size.