KTL
ktl::trivial_vector< T, Alloc > Class Template Reference

A dynamically allocated vector or trivial types. More...

#include <trivial_vector.h>

Public Types

typedef T * iterator
 
typedef const T * const_iterator
 
typedef std::reverse_iterator< T * > reverse_iterator
 
typedef std::reverse_iterator< const T * > const_reverse_iterator
 

Public Member Functions

 trivial_vector () noexcept
 Construct the vector with a default constructed allocator. More...
 
 trivial_vector (const Alloc &allocator) noexcept
 Construct the vector with the given allocator. More...
 
 trivial_vector (size_t n, const Alloc &allocator=Alloc())
 Construct the vector with the given allocator and initial size. More...
 
 trivial_vector (size_t n, const T &value, const Alloc &allocator=Alloc())
 Construct the vector with the given allocator, initial size and default value. More...
 
 trivial_vector (std::initializer_list< T > initializer, const Alloc &allocator=Alloc())
 Construct the vector with the allocator and range of values. More...
 
 trivial_vector (const T *first, const T *last, const Alloc &allocator=Alloc())
 Construct the vector with the allocator and range of values. More...
 
 trivial_vector (const trivial_vector &other) noexcept
 
 trivial_vector (trivial_vector &&other) noexcept
 
 trivial_vector (const trivial_vector &other, const Alloc &allocator) noexcept
 
 trivial_vector (trivial_vector &&other, const Alloc &allocator) noexcept
 
 ~trivial_vector () noexcept
 
trivial_vectoroperator= (const trivial_vector &other) noexcept
 
trivial_vectoroperator= (trivial_vector &&other) noexcept
 
T & operator[] (size_t index) noexcept
 Returns a reference to the element at index. More...
 
const T & operator[] (size_t index) const noexcept
 Returns a reference to the element at index. More...
 
iterator begin () noexcept
 
const_iterator begin () const noexcept
 
iterator end () noexcept
 
const_iterator end () const noexcept
 
reverse_iterator rbegin () noexcept
 
const_reverse_iterator rbegin () const noexcept
 
reverse_iterator rend () noexcept
 
const_reverse_iterator rend () const noexcept
 
size_t size () const noexcept
 Returns the current size of the vector. More...
 
size_t capacity () const noexcept
 Returns the current capacity of the vector. More...
 
bool empty () const noexcept
 Returns true if the vector has no elements. More...
 
iterator data () noexcept
 Returns an iterator to the start of the vector. More...
 
const_iterator data () const noexcept
 Returns a const iterator to the start of the vector. More...
 
T & at (size_t index) const noexcept
 Returns a reference to the element at index. More...
 
void resize (size_t n) noexcept
 Resizes the vector to the given size. More...
 
void reserve (size_t n) noexcept
 Reserves the capacity of the vector to n, without initializing any elements. More...
 
iterator push_back (const T &element) noexcept
 Pushes a new element into the vector by copying it. More...
 
iterator push_back (T &&element) noexcept
 Pushes a new element into the vector by moving it. More...
 
iterator push_back (const T *first, const T *last) noexcept
 Pushes a range of values into the vector. More...
 
template<typename... Args>
iterator emplace_back (Args &&... args) noexcept
 Pushes a new element into the vector by constructing it. More...
 
template<typename... Args>
void emplace (const_iterator iter, Args &&... args) noexcept
 Inserts a new element into the vector by constructing it. More...
 
iterator erase (const_iterator iter) noexcept
 Erases the element pointed to by the iterator. More...
 
iterator erase (const_iterator first, const_iterator last) noexcept
 Erases all elements in a range. More...
 
pop_back () noexcept
 Removes the last element from the vector and returns it. More...
 
void clear () noexcept
 Clears all elements in the vector. More...
 

Detailed Description

template<typename T, typename Alloc>
class ktl::trivial_vector< T, Alloc >

A dynamically allocated vector or trivial types.

Template Parameters
TThe type to use. Must be trivially copyable and default constructible
AllocThe type of allocoator to use

Member Typedef Documentation

◆ const_iterator

template<typename T , typename Alloc >
typedef const T* ktl::trivial_vector< T, Alloc >::const_iterator

◆ const_reverse_iterator

template<typename T , typename Alloc >
typedef std::reverse_iterator<const T*> ktl::trivial_vector< T, Alloc >::const_reverse_iterator

◆ iterator

template<typename T , typename Alloc >
typedef T* ktl::trivial_vector< T, Alloc >::iterator

◆ reverse_iterator

template<typename T , typename Alloc >
typedef std::reverse_iterator<T*> ktl::trivial_vector< T, Alloc >::reverse_iterator

Constructor & Destructor Documentation

◆ trivial_vector() [1/10]

template<typename T , typename Alloc >
ktl::trivial_vector< T, Alloc >::trivial_vector ( )
inlinenoexcept

Construct the vector with a default constructed allocator.

◆ trivial_vector() [2/10]

template<typename T , typename Alloc >
ktl::trivial_vector< T, Alloc >::trivial_vector ( const Alloc &  allocator)
inlineexplicitnoexcept

Construct the vector with the given allocator.

Parameters
allocatorThe allocator to use

◆ trivial_vector() [3/10]

template<typename T , typename Alloc >
ktl::trivial_vector< T, Alloc >::trivial_vector ( size_t  n,
const Alloc &  allocator = Alloc() 
)
inlineexplicit

Construct the vector with the given allocator and initial size.

Parameters
nThe initial size of the vector
allocatorThe allocator to use. Will be default constructed if unspecified

◆ trivial_vector() [4/10]

template<typename T , typename Alloc >
ktl::trivial_vector< T, Alloc >::trivial_vector ( size_t  n,
const T &  value,
const Alloc &  allocator = Alloc() 
)
inlineexplicit

Construct the vector with the given allocator, initial size and default value.

Parameters
nThe initial size of the vector
valueThe value to initialize every element as
allocatorThe allocator to use. Will be default constructed if unspecified

◆ trivial_vector() [5/10]

template<typename T , typename Alloc >
ktl::trivial_vector< T, Alloc >::trivial_vector ( std::initializer_list< T >  initializer,
const Alloc &  allocator = Alloc() 
)
inline

Construct the vector with the allocator and range of values.

Parameters
initializerThe initial set of values
allocatorThe allocator to use. Will be default constructed if unspecified

◆ trivial_vector() [6/10]

template<typename T , typename Alloc >
ktl::trivial_vector< T, Alloc >::trivial_vector ( const T *  first,
const T *  last,
const Alloc &  allocator = Alloc() 
)
inlineexplicit

Construct the vector with the allocator and range of values.

Parameters
firstA pointer to the first element
lastA pointer past the last element
allocatorThe allocator to use. Will be default constructed if unspecified

◆ trivial_vector() [7/10]

template<typename T , typename Alloc >
ktl::trivial_vector< T, Alloc >::trivial_vector ( const trivial_vector< T, Alloc > &  other)
inlinenoexcept

◆ trivial_vector() [8/10]

template<typename T , typename Alloc >
ktl::trivial_vector< T, Alloc >::trivial_vector ( trivial_vector< T, Alloc > &&  other)
inlinenoexcept

◆ trivial_vector() [9/10]

template<typename T , typename Alloc >
ktl::trivial_vector< T, Alloc >::trivial_vector ( const trivial_vector< T, Alloc > &  other,
const Alloc &  allocator 
)
inlinenoexcept

◆ trivial_vector() [10/10]

template<typename T , typename Alloc >
ktl::trivial_vector< T, Alloc >::trivial_vector ( trivial_vector< T, Alloc > &&  other,
const Alloc &  allocator 
)
inlinenoexcept

◆ ~trivial_vector()

template<typename T , typename Alloc >
ktl::trivial_vector< T, Alloc >::~trivial_vector ( )
inlinenoexcept

Member Function Documentation

◆ at()

template<typename T , typename Alloc >
T& ktl::trivial_vector< T, Alloc >::at ( size_t  index) const
inlinenoexcept

Returns a reference to the element at index.

Note
An index higher than size() will produce undefined behaviour.
Parameters
indexThe index of the element in the vector. Must be less than size().
Returns
A reference to the element at index.

◆ begin() [1/2]

template<typename T , typename Alloc >
const_iterator ktl::trivial_vector< T, Alloc >::begin ( ) const
inlinenoexcept

◆ begin() [2/2]

template<typename T , typename Alloc >
iterator ktl::trivial_vector< T, Alloc >::begin ( )
inlinenoexcept

◆ capacity()

template<typename T , typename Alloc >
size_t ktl::trivial_vector< T, Alloc >::capacity ( ) const
inlinenoexcept

Returns the current capacity of the vector.

Returns
The current capacity of the vector in number of elements.

◆ clear()

template<typename T , typename Alloc >
void ktl::trivial_vector< T, Alloc >::clear ( )
inlinenoexcept

Clears all elements in the vector.

◆ data() [1/2]

template<typename T , typename Alloc >
const_iterator ktl::trivial_vector< T, Alloc >::data ( ) const
inlinenoexcept

Returns a const iterator to the start of the vector.

Returns
A const iterator to the start of the vector.

◆ data() [2/2]

template<typename T , typename Alloc >
iterator ktl::trivial_vector< T, Alloc >::data ( )
inlinenoexcept

Returns an iterator to the start of the vector.

Returns
An iterator to the start of the vector.

◆ emplace()

template<typename T , typename Alloc >
template<typename... Args>
void ktl::trivial_vector< T, Alloc >::emplace ( const_iterator  iter,
Args &&...  args 
)
inlinenoexcept

Inserts a new element into the vector by constructing it.

Template Parameters
...ArgsVariadic template arguments.
Parameters
iterAn iterator pointing to the location where the new element should be emplaced.
...argsAny arguments to use in the construction of the element.
Returns
An iterator to the element that was added.

◆ emplace_back()

template<typename T , typename Alloc >
template<typename... Args>
iterator ktl::trivial_vector< T, Alloc >::emplace_back ( Args &&...  args)
inlinenoexcept

Pushes a new element into the vector by constructing it.

Template Parameters
...ArgsVariadic template arguments.
Parameters
...argsAny arguments to use in the construction of the element.
Returns
An iterator to the element that was added.

◆ empty()

template<typename T , typename Alloc >
bool ktl::trivial_vector< T, Alloc >::empty ( ) const
inlinenoexcept

Returns true if the vector has no elements.

Returns
Whether the vector has a size of 0.

◆ end() [1/2]

template<typename T , typename Alloc >
const_iterator ktl::trivial_vector< T, Alloc >::end ( ) const
inlinenoexcept

◆ end() [2/2]

template<typename T , typename Alloc >
iterator ktl::trivial_vector< T, Alloc >::end ( )
inlinenoexcept

◆ erase() [1/2]

template<typename T , typename Alloc >
iterator ktl::trivial_vector< T, Alloc >::erase ( const_iterator  first,
const_iterator  last 
)
inlinenoexcept

Erases all elements in a range.

Parameters
firstAn iterator pointing to the first element.
lastAn iterator pointing to the location after the last element.
Returns
An iterator pointing to the element immidiately after the erased ones.

◆ erase() [2/2]

template<typename T , typename Alloc >
iterator ktl::trivial_vector< T, Alloc >::erase ( const_iterator  iter)
inlinenoexcept

Erases the element pointed to by the iterator.

Parameters
iterAn iterator pointing to the element.
Returns
An iterator pointing to the element immidiately after the erased one.

◆ operator=() [1/2]

template<typename T , typename Alloc >
trivial_vector& ktl::trivial_vector< T, Alloc >::operator= ( const trivial_vector< T, Alloc > &  other)
inlinenoexcept

◆ operator=() [2/2]

template<typename T , typename Alloc >
trivial_vector& ktl::trivial_vector< T, Alloc >::operator= ( trivial_vector< T, Alloc > &&  other)
inlinenoexcept

◆ operator[]() [1/2]

template<typename T , typename Alloc >
const T& ktl::trivial_vector< T, Alloc >::operator[] ( size_t  index) const
inlinenoexcept

Returns a reference to the element at index.

Note
An index higher than size() will produce undefined behaviour.
Parameters
indexThe index of the element in the array. Must be less than size().
Returns
A reference to the element at index.

◆ operator[]() [2/2]

template<typename T , typename Alloc >
T& ktl::trivial_vector< T, Alloc >::operator[] ( size_t  index)
inlinenoexcept

Returns a reference to the element at index.

Note
An index higher than size() will produce undefined behaviour.
Parameters
indexThe index of the element in the array. Must be less than size().
Returns
A reference to the element at index.

◆ pop_back()

template<typename T , typename Alloc >
T ktl::trivial_vector< T, Alloc >::pop_back ( )
inlinenoexcept

Removes the last element from the vector and returns it.

Returns
The last element in the vector.

◆ push_back() [1/3]

template<typename T , typename Alloc >
iterator ktl::trivial_vector< T, Alloc >::push_back ( const T &  element)
inlinenoexcept

Pushes a new element into the vector by copying it.

Parameters
valueThe element to copy into the vector.
Returns
An iterator to the element that was added.

◆ push_back() [2/3]

template<typename T , typename Alloc >
iterator ktl::trivial_vector< T, Alloc >::push_back ( const T *  first,
const T *  last 
)
inlinenoexcept

Pushes a range of values into the vector.

Parameters
firstA pointer to the first element.
lastA pointer one element past the last element.
Returns
An iterator to the element that was added.

◆ push_back() [3/3]

template<typename T , typename Alloc >
iterator ktl::trivial_vector< T, Alloc >::push_back ( T &&  element)
inlinenoexcept

Pushes a new element into the vector by moving it.

Parameters
valueThe element to move into the vector.
Returns
An iterator to the element that was added.

◆ rbegin() [1/2]

template<typename T , typename Alloc >
const_reverse_iterator ktl::trivial_vector< T, Alloc >::rbegin ( ) const
inlinenoexcept

◆ rbegin() [2/2]

template<typename T , typename Alloc >
reverse_iterator ktl::trivial_vector< T, Alloc >::rbegin ( )
inlinenoexcept

◆ rend() [1/2]

template<typename T , typename Alloc >
const_reverse_iterator ktl::trivial_vector< T, Alloc >::rend ( ) const
inlinenoexcept

◆ rend() [2/2]

template<typename T , typename Alloc >
reverse_iterator ktl::trivial_vector< T, Alloc >::rend ( )
inlinenoexcept

◆ reserve()

template<typename T , typename Alloc >
void ktl::trivial_vector< T, Alloc >::reserve ( size_t  n)
inlinenoexcept

Reserves the capacity of the vector to n, without initializing any elements.

Parameters
nThe minimum capacity of the vector.

◆ resize()

template<typename T , typename Alloc >
void ktl::trivial_vector< T, Alloc >::resize ( size_t  n)
inlinenoexcept

Resizes the vector to the given size.

Parameters
nThe size to resize to.

◆ size()

template<typename T , typename Alloc >
size_t ktl::trivial_vector< T, Alloc >::size ( ) const
inlinenoexcept

Returns the current size of the vector.

Returns
The current size of the vector in number of elements.

The documentation for this class was generated from the following file: