Vector

Vectors are sequence containers representing arrays that can change in size.

Just like arrays, vectors use contiguous storage locations for their elements, which means that their elements can also be accessed using offsets on regular pointers to its elements, and just as efficiently as in arrays. But unlike arrays, their size can change dynamically, with their storage being handled automatically by the container.

Instead, vector containers may allocate some extra storage to accommodate for possible growth, and thus the container may have an actual capacity greater than the storage strictly needed to contain its elements (i.e., its size). Libraries can implement different strategies for growth to balance between memory usage and reallocations, but in any case, reallocations should only happen at logarithmically growing intervals of size so that the insertion of individual elements at the end of the vector can be provided with amortized constant time complexity (see push_back).

Therefore, compared to arrays, vectors consume more memory in exchange for the ability to manage storage and grow dynamically in an efficient way.

Vector can have preallocated (stack) space for N elements.

Template parameters:

_Type = element type.

N Number of preallocated space for elements.

_Allocator Type of the allocator object used to define the storage allocation model. By default DefaultAllocator is used.

More...

Members

Aliases

Storage
alias Storage = .Storage!(_Type, N, _allowHeap)
Undocumented in source.

Structs

Vector
struct Vector
Undocumented in source.

Variables

_allowHeap
enum bool _allowHeap;
Undocumented in source.
_hasStatelessAllocator
enum bool _hasStatelessAllocator;
Undocumented in source.

Detailed Description

@safe:

* Inserting element to Vector pointer is @safe if constructor of element is @safe (assumption is that constructor doesn't leak this pointer).

* Vector assume that deallocation with custom allocator is @safe if allocation is @safe even if method deallcoate is @system.

* Methods returning reference/pointer/slice (front(), back(), ptr(), elements(), opSlice(), ...) to vector elements are all @system because increasing capacity of vector can realocate all elements to new memory location and invalidate external references to old location.

scope and -dip1000:

* Vector assume that managed object have global lifetime (scope can be ignored).

* Functions for inserting elements to vector have non scope parameters (global lifetime).

Meta