[ Web Proxy ]
URL:
Viewing: https://ko.cppreference.com/cpp/container/vector [Back]  [Original]

std::vector - cppreference.com
cppreference.com

std::vector

cppreference.com
<tbody> </tbody>
<vector> .
template< class T, class Allocator = std::allocator<T> > class vector;

std::vector (sequence) .

, . . This means that a pointer to an element of a vector may be passed to any function that expects a pointer to an element of an array. (since C++03)

The storage of the vector is handled automatically, being expanded and contracted as needed. Vectors usually occupy more space than static arrays, because more memory is allocated to handle future growth. This way a vector does not need to reallocate each time an element is inserted, but only when the additional memory is exhausted. The total amount of allocated memory can be queried using capacity() function. Extra memory can be returned to the system via a call to shrink_to_fit().

Reallocations are usually costly operations in terms of performance. reserve() function can be used to eliminate reallocations if the number of elements is known beforehand.

. :

  • - O(1)
  • / - (amortized) O(1)
  • / - O(n)

std::vector meets the requirements of Container, AllocatorAwareContainer, SequenceContainer and ReversibleContainer.

Template parameters

T - .
T CopyAssignable CopyConstructible . (until C++11)
. , MoveConstructible MoveAssignable , . (since C++11)

[edit]

Allocator - (allocator). Allocator . [edit]

Specializations

bool std::vector .

space-efficient dynamic bitset
(class template specialization) [edit]

Member types

Member type Definition
value_type T [edit]
allocator_type [edit]
size_type (unsigned int) ( std::size_t) [edit]
difference_type (signed int) ( std::ptrdiff_t) [edit]
reference Allocator::reference (until C++11)
value_type& (since C++11) [edit]
const_reference Allocator::const_reference (until C++11)
const value_type& (since C++11) [edit]
pointer Allocator::pointer (until C++11)
std::allocator_traits<Allocator>::pointer (since C++11) [edit]
const_pointer Allocator::const_pointer (until C++11)
std::allocator_traits<Allocator>::const_pointer (since C++11) [edit]
iterator RandomAccessIterator [edit]
const_iterator (constant) (iterator) [edit]
reverse_iterator std::reverse_iterator<iterator> [edit]
const_reverse_iterator std::reverse_iterator<const_iterator> [edit]

Member functions

vector .
(public member function) [edit]
vector .
(public member function) [edit]
.
(public member function) [edit]
.
(public member function) [edit]
.
(public member function) [edit]
Element access
access specified element with bounds checking
(public member function) [edit]

(public member function) [edit]
.
(public member function) [edit]
.
(public member function) [edit]
(C++11)
direct access to the underlying array
(public member function) [edit]
Iterators
(iterator) .
(public member function) [edit]
(iterator) .
(public member function) [edit]
(reverse iterator) .
(public member function) [edit]
(reverse iterator) .
(public member function) [edit]
Capacity
.
(public member function) [edit]
.
(public member function) [edit]
.
(public member function) [edit]
reserves storage
(public member function) [edit]
returns the number of elements that can be held in currently allocated storage
(public member function) [edit]
reduces memory usage by freeing unused memory
(public member function) [edit]
Modifiers
.
(public member function) [edit]
.
(public member function) [edit]
(C++11)
.
(public member function) [edit]

(public member function) [edit]
.
(public member function) [edit]
constructs elements in-place at the end
(public member function) [edit]

(public member function) [edit]

(public member function) [edit]

(public member function) [edit]

Non-member functions

lexicographically compares the values in the vector
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]

Web Proxy Viewer  |  New URL  |  Original Page