Games Task Scheduler (GTS)
A multi-processor scheduling framework for games engines
gts::Vector< T, TAllocator > Class Template Reference

A re-sizable array-like ADT. A subset of the STL Vector interface. More...

#include <Vector.h>

Inherits gts::AlignedAllocator< GTS_NO_SHARING_CACHE_LINE_SIZE >.

Public Types

using size_type = size_t
 
using value_type = T
 
using allocator_type = TAllocator
 

Public Member Functions

 ~Vector ()
 Destructs the container. The destructors of the elements are called and the used storage is deallocated.
 
 Vector (const allocator_type &allocator=allocator_type())
 Constructs an empty container with the given 'allocator'.
 
 Vector (size_type count, const allocator_type &allocator=allocator_type())
 Constructs the container with 'count' copies of default constructed values.
 
 Vector (size_type count, value_type const &fill, const allocator_type &alloc=allocator_type())
 Constructs the container with 'count' copies of elements with value 'fill'.
 
 Vector (std::initializer_list< value_type > initList, const allocator_type &alloc=allocator_type())
 Constructs the container with an InitializerList.
 
 Vector (Vector const &other)
 Copy constructor. Constructs the container with the copy of the contents of 'other'.
 
 Vector (Vector &&other)
 Move constructor. Constructs the container with the contents of other using move semantics. After the move, other is invalid.
 
Vectoroperator= (Vector const &other)
 Copy assignment operator. Replaces the contents with a copy of the contents of 'other'.
 
Vectoroperator= (Vector &&other)
 Move assignment operator. Replaces the contents with those of other using move semantics. After the move, other is invalid.
 
bool empty () const
 Checks if the contains has no elements. More...
 
size_type size () const
 Gets the number of elements in the container. More...
 
size_type capacity () const
 Gets the number of elements that can be held in the currently allocated storage. More...
 
value_type const * begin () const
 Gets a pointer to the first element;. More...
 
value_type * begin ()
 Gets a pointer to the first element;. More...
 
value_type const * end () const
 Gets a pointer to one past the last element;. More...
 
value_type * end ()
 Gets a pointer to one past the last element;. More...
 
value_type const & front () const
 Gets the first element. More...
 
value_type & front ()
 Gets the first element. More...
 
value_type const & back () const
 Gets the last element. More...
 
value_type & back ()
 Gets the last element. More...
 
value_type const & operator[] (size_type pos) const
 Gets the element at pos. More...
 
value_type & operator[] (size_type pos)
 Gets the element at pos. More...
 
value_type const * data () const
 A pointer to the underlying storage array. More...
 
value_type * data ()
 A pointer to the underlying storage array. More...
 
allocator_type get_allocator () const
 Get this Vectors allocator. More...
 
void push_back (value_type const &val)
 
void push_back (value_type &&val)
 
template<typename... TArgs>
void emplace_back (TArgs &&... args)
 
void pop_back ()
 
void resize (size_type count)
 
void resize (size_type count, value_type const &fill)
 
void reserve (size_type count)
 
void shrink_to_fit ()
 
void clear ()
 
template<typename... TArgs>
void emplace_back (TArgs &&... args)
 
template<typename... TArgs>
void _init (size_type count, TArgs &&... args)
 

Detailed Description

template<typename T, typename TAllocator = AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
class gts::Vector< T, TAllocator >

A re-sizable array-like ADT. A subset of the STL Vector interface.

Template Parameters
TThe element type stored in the container.
TAllocatorThe allocator used by the storage backing.

Member Function Documentation

◆ back() [1/2]

template<typename T , typename TAllocator = AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
T & Vector::back ( )

Gets the last element.

Returns
An element.

◆ back() [2/2]

template<typename T , typename TAllocator = AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
T const & Vector::back ( ) const

Gets the last element.

Returns
An element.

◆ begin() [1/2]

template<typename T , typename TAllocator = AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
T * Vector::begin ( )

Gets a pointer to the first element;.

Returns
An element pointer.

◆ begin() [2/2]

template<typename T , typename TAllocator = AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
T const * Vector::begin ( ) const

Gets a pointer to the first element;.

Returns
An element pointer.

◆ capacity()

template<typename T , typename TAllocator = AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
Vector< T, TAllocator >::size_type Vector::capacity ( ) const

Gets the number of elements that can be held in the currently allocated storage.

Returns
The capacity.

◆ clear()

template<typename T , typename TAllocator = AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
void Vector::clear ( )

Removes all elements but does not destroy the underlying array.

◆ data() [1/2]

template<typename T , typename TAllocator = AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
T * Vector::data ( )

A pointer to the underlying storage array.

Returns
The storage array.

◆ data() [2/2]

template<typename T , typename TAllocator = AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
T const * Vector::data ( ) const

A pointer to the underlying storage array.

Returns
The storage array.

◆ emplace_back()

template<typename T , typename TAllocator = AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
template<typename... TArgs>
void gts::Vector< T, TAllocator >::emplace_back ( TArgs &&...  args)

Construct a new element at the end.

◆ empty()

template<typename T , typename TAllocator = AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
bool Vector::empty ( ) const

Checks if the contains has no elements.

Returns
True if empty, false otherwise.

◆ end() [1/2]

template<typename T , typename TAllocator = AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
T * Vector::end ( )

Gets a pointer to one past the last element;.

Returns
An element pointer.

◆ end() [2/2]

template<typename T , typename TAllocator = AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
T const * Vector::end ( ) const

Gets a pointer to one past the last element;.

Returns
An element pointer.

◆ front() [1/2]

template<typename T , typename TAllocator = AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
T & Vector::front ( )

Gets the first element.

Returns
An element.

◆ front() [2/2]

template<typename T , typename TAllocator = AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
T const & Vector::front ( ) const

Gets the first element.

Returns
An element.

◆ get_allocator()

template<typename T , typename TAllocator = AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
Vector< T, TAllocator >::allocator_type Vector::get_allocator ( ) const

Get this Vectors allocator.

Returns
The allocator.

◆ operator[]() [1/2]

template<typename T , typename TAllocator = AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
T & Vector::operator[] ( size_type  pos)

Gets the element at pos.

Returns
An element.

◆ operator[]() [2/2]

template<typename T , typename TAllocator = AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
T const & Vector::operator[] ( size_type  pos) const

Gets the element at pos.

Returns
An element.

◆ pop_back()

template<typename T , typename TAllocator = AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
void Vector::pop_back ( )

Removes and destroys the element at the end.

◆ push_back() [1/2]

template<typename T , typename TAllocator = AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
void gts::Vector< T, TAllocator >::push_back ( value_type &&  val)

Moves 'val' to the end.

◆ push_back() [2/2]

template<typename T , typename TAllocator = AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
void gts::Vector< T, TAllocator >::push_back ( value_type const &  val)

Copies 'val' to the end.

◆ reserve()

template<typename T , typename TAllocator = AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
void Vector::reserve ( size_type  count)

Grow the underlying array if count > capacity, otherwise it does nothing.

◆ resize() [1/2]

template<typename T , typename TAllocator = AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
void Vector::resize ( size_type  count)

Resize the vector to have 'count' elements. If count > size(), new will be default constructed.

◆ resize() [2/2]

template<typename T , typename TAllocator = AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
void gts::Vector< T, TAllocator >::resize ( size_type  count,
value_type const &  fill 
)

Resize the vector to have 'count' elements. If count > size(), new will be constructed with the value of 'fill'.

◆ shrink_to_fit()

template<typename T , typename TAllocator = AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
void Vector::shrink_to_fit ( )

Resize the array to size().

◆ size()

template<typename T , typename TAllocator = AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
Vector< T, TAllocator >::size_type Vector::size ( ) const

Gets the number of elements in the container.

Returns
The size.