LLGL 0.05 Beta
Loading...
Searching...
No Matches
LLGL::DynamicArray< T, Allocator > Class Template Reference

Generic container class for dynamic arrays that usually do not change in size. More...

#include <DynamicArray.h>

Public Types

using value_type = T
using size_type = std::size_t
using difference_type = std::ptrdiff_t
using reference = value_type&
using const_reference = const value_type&
using pointer = value_type*
using const_pointer = const value_type*
using iterator = value_type*
using const_iterator = const value_type*
using reverse_iterator = std::reverse_iterator<iterator>
using const_reverse_iterator = std::reverse_iterator<const_iterator>

Public Member Functions

 DynamicArray ()=default
 Default initializes an empty array.
 DynamicArray (std::nullptr_t)
 Equivalent to default constructor: initializes an empty array.
 DynamicArray (const DynamicArray &other)
 Initializes the array with a copy of all elements from the other array.
 DynamicArray (DynamicArray &&other) noexcept
 Takes the ownership of dynamically allocated elements from the other array.
template<typename InputIter>
 DynamicArray (InputIter from, InputIter to)
 Initializes the array with the specified elements in the half-open range [from, to).
 DynamicArray (size_type count, UninitializeTag)
 Initializes the array with the specified number of elements and initial default value.
 DynamicArray (size_type count, const value_type &value=value_type{})
 Initializes the array with the specified number of elements and initial value.
 ~DynamicArray ()
 Destroys all elements in this array.
bool empty () const noexcept
 Returns true if this array is empty.
size_type size () const noexcept
 Returns the size (in number of elements) of this array.
size_type capacity () const noexcept
 Convenience function to be partially compatible with std::vector<T>. Equivalent to size().
pointer data () noexcept
 Returns a pointer to the beginning of this array.
const_pointer data () const noexcept
 Returns a constant pointer to the beginning of this array.
pointer get () noexcept
 Convenience function to be partially compatible with std::unique_ptr<T[]>. Equivalent to data().
const_pointer get () const noexcept
 Convenience function to be partially compatible with std::unique_ptr<T[]>. Equivalent to data().
reference at (size_type pos)
 Returns a reference to the element at the specified position in this array.
const_reference at (size_type pos) const
 Returns a constant reference to the element at the specified position in this array.
reference front ()
 Returns a reference to first element in this array.
const_reference front () const
 Returns a constant reference to first element in this array.
reference back ()
 Returns a reference to last element in this array.
const_reference back () const
 Returns a constant reference to last element in this array.
void clear ()
 Release the internal memory.
pointer release ()
 Release the ownership of the internally allocated memory.
void resize (size_type newSize, UninitializeTag)
 Resizes this array to the new size if the new size is larger than the old size. This will also leave all new elements uninitialized.
void resize (size_type newSize, const value_type &value)
 Resizes this array to the new size if the new size is larger than the old size and explicitly initializes all newly allocated elements.
void swap (DynamicArray &other) noexcept
iterator begin () noexcept
const_iterator begin () const noexcept
const_iterator cbegin () const noexcept
reverse_iterator rbegin ()
const_reverse_iterator rbegin () const
const_reverse_iterator crbegin () const
iterator end () noexcept
const_iterator end () const noexcept
const_iterator cend () const noexcept
reverse_iterator rend ()
const_reverse_iterator rend () const
const_reverse_iterator crend () const
DynamicArray & operator= (const DynamicArray &rhs)
DynamicArray & operator= (DynamicArray &&rhs) noexcept(std::is_nothrow_destructible< T >::value)
const_reference operator[] (size_type pos) const
reference operator[] (size_type pos)
 operator ArrayView< T > () const
 operator bool () const
 Returns true if this array is non-empty.

Detailed Description

template<typename T, typename Allocator = std::allocator<T>>
class LLGL::DynamicArray< T, Allocator >

Generic container class for dynamic arrays that usually do not change in size.

Remarks
Because this container does not support push_back, pop_back, or insert functionality, it only supports trivially constructible and trivially copyable types.
Template Parameters
TSpecifies the array element type.
AllocatorSpecifies the memory allocator. This has to be compatible with std::allocator. By default std::allocator<T>.

Member Typedef Documentation

◆ const_iterator

template<typename T, typename Allocator = std::allocator<T>>
using LLGL::DynamicArray< T, Allocator >::const_iterator = const value_type*

◆ const_pointer

template<typename T, typename Allocator = std::allocator<T>>
using LLGL::DynamicArray< T, Allocator >::const_pointer = const value_type*

◆ const_reference

template<typename T, typename Allocator = std::allocator<T>>
using LLGL::DynamicArray< T, Allocator >::const_reference = const value_type&

◆ const_reverse_iterator

template<typename T, typename Allocator = std::allocator<T>>
using LLGL::DynamicArray< T, Allocator >::const_reverse_iterator = std::reverse_iterator<const_iterator>

◆ difference_type

template<typename T, typename Allocator = std::allocator<T>>
using LLGL::DynamicArray< T, Allocator >::difference_type = std::ptrdiff_t

◆ iterator

template<typename T, typename Allocator = std::allocator<T>>
using LLGL::DynamicArray< T, Allocator >::iterator = value_type*

◆ pointer

template<typename T, typename Allocator = std::allocator<T>>
using LLGL::DynamicArray< T, Allocator >::pointer = value_type*

◆ reference

template<typename T, typename Allocator = std::allocator<T>>
using LLGL::DynamicArray< T, Allocator >::reference = value_type&

◆ reverse_iterator

template<typename T, typename Allocator = std::allocator<T>>
using LLGL::DynamicArray< T, Allocator >::reverse_iterator = std::reverse_iterator<iterator>

◆ size_type

template<typename T, typename Allocator = std::allocator<T>>
using LLGL::DynamicArray< T, Allocator >::size_type = std::size_t

◆ value_type

template<typename T, typename Allocator = std::allocator<T>>
using LLGL::DynamicArray< T, Allocator >::value_type = T

Constructor & Destructor Documentation

◆ DynamicArray() [1/7]

template<typename T, typename Allocator = std::allocator<T>>
LLGL::DynamicArray< T, Allocator >::DynamicArray ( )
default

Default initializes an empty array.

◆ DynamicArray() [2/7]

template<typename T, typename Allocator = std::allocator<T>>
LLGL::DynamicArray< T, Allocator >::DynamicArray ( std::nullptr_t )
inline

Equivalent to default constructor: initializes an empty array.

◆ DynamicArray() [3/7]

template<typename T, typename Allocator = std::allocator<T>>
LLGL::DynamicArray< T, Allocator >::DynamicArray ( const DynamicArray< T, Allocator > & other)
inline

Initializes the array with a copy of all elements from the other array.

◆ DynamicArray() [4/7]

template<typename T, typename Allocator = std::allocator<T>>
LLGL::DynamicArray< T, Allocator >::DynamicArray ( DynamicArray< T, Allocator > && other)
inlinenoexcept

Takes the ownership of dynamically allocated elements from the other array.

◆ DynamicArray() [5/7]

template<typename T, typename Allocator = std::allocator<T>>
template<typename InputIter>
LLGL::DynamicArray< T, Allocator >::DynamicArray ( InputIter from,
InputIter to )
inline

Initializes the array with the specified elements in the half-open range [from, to).

◆ DynamicArray() [6/7]

template<typename T, typename Allocator = std::allocator<T>>
LLGL::DynamicArray< T, Allocator >::DynamicArray ( size_type count,
UninitializeTag  )
inlineexplicit

Initializes the array with the specified number of elements and initial default value.

◆ DynamicArray() [7/7]

template<typename T, typename Allocator = std::allocator<T>>
LLGL::DynamicArray< T, Allocator >::DynamicArray ( size_type count,
const value_type & value = value_type{} )
inlineexplicit

Initializes the array with the specified number of elements and initial value.

◆ ~DynamicArray()

template<typename T, typename Allocator = std::allocator<T>>
LLGL::DynamicArray< T, Allocator >::~DynamicArray ( )
inline

Destroys all elements in this array.

Member Function Documentation

◆ at() [1/2]

template<typename T, typename Allocator = std::allocator<T>>
reference LLGL::DynamicArray< T, Allocator >::at ( size_type pos)
inline

Returns a reference to the element at the specified position in this array.

Remarks
This must not be called on an empty array!

◆ at() [2/2]

template<typename T, typename Allocator = std::allocator<T>>
const_reference LLGL::DynamicArray< T, Allocator >::at ( size_type pos) const
inline

Returns a constant reference to the element at the specified position in this array.

Remarks
This must not be called on an empty array!

◆ back() [1/2]

template<typename T, typename Allocator = std::allocator<T>>
reference LLGL::DynamicArray< T, Allocator >::back ( )
inline

Returns a reference to last element in this array.

Remarks
This must not be called on an empty array!

◆ back() [2/2]

template<typename T, typename Allocator = std::allocator<T>>
const_reference LLGL::DynamicArray< T, Allocator >::back ( ) const
inline

Returns a constant reference to last element in this array.

Remarks
This must not be called on an empty array!

◆ begin() [1/2]

template<typename T, typename Allocator = std::allocator<T>>
const_iterator LLGL::DynamicArray< T, Allocator >::begin ( ) const
inlinenoexcept

◆ begin() [2/2]

template<typename T, typename Allocator = std::allocator<T>>
iterator LLGL::DynamicArray< T, Allocator >::begin ( )
inlinenoexcept

◆ capacity()

template<typename T, typename Allocator = std::allocator<T>>
size_type LLGL::DynamicArray< T, Allocator >::capacity ( ) const
inlinenoexcept

Convenience function to be partially compatible with std::vector<T>. Equivalent to size().

◆ cbegin()

template<typename T, typename Allocator = std::allocator<T>>
const_iterator LLGL::DynamicArray< T, Allocator >::cbegin ( ) const
inlinenoexcept

◆ cend()

template<typename T, typename Allocator = std::allocator<T>>
const_iterator LLGL::DynamicArray< T, Allocator >::cend ( ) const
inlinenoexcept

◆ clear()

template<typename T, typename Allocator = std::allocator<T>>
void LLGL::DynamicArray< T, Allocator >::clear ( )
inline

Release the internal memory.

Remarks
After this call, size() and capacity() return 0.

◆ crbegin()

template<typename T, typename Allocator = std::allocator<T>>
const_reverse_iterator LLGL::DynamicArray< T, Allocator >::crbegin ( ) const
inline

◆ crend()

template<typename T, typename Allocator = std::allocator<T>>
const_reverse_iterator LLGL::DynamicArray< T, Allocator >::crend ( ) const
inline

◆ data() [1/2]

template<typename T, typename Allocator = std::allocator<T>>
const_pointer LLGL::DynamicArray< T, Allocator >::data ( ) const
inlinenoexcept

Returns a constant pointer to the beginning of this array.

◆ data() [2/2]

template<typename T, typename Allocator = std::allocator<T>>
pointer LLGL::DynamicArray< T, Allocator >::data ( )
inlinenoexcept

Returns a pointer to the beginning of this array.

◆ empty()

template<typename T, typename Allocator = std::allocator<T>>
bool LLGL::DynamicArray< T, Allocator >::empty ( ) const
inlinenoexcept

Returns true if this array is empty.

◆ end() [1/2]

template<typename T, typename Allocator = std::allocator<T>>
const_iterator LLGL::DynamicArray< T, Allocator >::end ( ) const
inlinenoexcept

◆ end() [2/2]

template<typename T, typename Allocator = std::allocator<T>>
iterator LLGL::DynamicArray< T, Allocator >::end ( )
inlinenoexcept

◆ front() [1/2]

template<typename T, typename Allocator = std::allocator<T>>
reference LLGL::DynamicArray< T, Allocator >::front ( )
inline

Returns a reference to first element in this array.

Remarks
This must not be called on an empty array!

◆ front() [2/2]

template<typename T, typename Allocator = std::allocator<T>>
const_reference LLGL::DynamicArray< T, Allocator >::front ( ) const
inline

Returns a constant reference to first element in this array.

Remarks
This must not be called on an empty array!

◆ get() [1/2]

template<typename T, typename Allocator = std::allocator<T>>
const_pointer LLGL::DynamicArray< T, Allocator >::get ( ) const
inlinenoexcept

Convenience function to be partially compatible with std::unique_ptr<T[]>. Equivalent to data().

◆ get() [2/2]

template<typename T, typename Allocator = std::allocator<T>>
pointer LLGL::DynamicArray< T, Allocator >::get ( )
inlinenoexcept

Convenience function to be partially compatible with std::unique_ptr<T[]>. Equivalent to data().

◆ operator ArrayView< T >()

template<typename T, typename Allocator = std::allocator<T>>
LLGL::DynamicArray< T, Allocator >::operator ArrayView< T > ( ) const
inline

◆ operator bool()

template<typename T, typename Allocator = std::allocator<T>>
LLGL::DynamicArray< T, Allocator >::operator bool ( ) const
inline

Returns true if this array is non-empty.

◆ operator=() [1/2]

template<typename T, typename Allocator = std::allocator<T>>
DynamicArray & LLGL::DynamicArray< T, Allocator >::operator= ( const DynamicArray< T, Allocator > & rhs)
inline

◆ operator=() [2/2]

template<typename T, typename Allocator = std::allocator<T>>
DynamicArray & LLGL::DynamicArray< T, Allocator >::operator= ( DynamicArray< T, Allocator > && rhs)
inlinenoexcept

◆ operator[]() [1/2]

template<typename T, typename Allocator = std::allocator<T>>
reference LLGL::DynamicArray< T, Allocator >::operator[] ( size_type pos)
inline

◆ operator[]() [2/2]

template<typename T, typename Allocator = std::allocator<T>>
const_reference LLGL::DynamicArray< T, Allocator >::operator[] ( size_type pos) const
inline

◆ rbegin() [1/2]

template<typename T, typename Allocator = std::allocator<T>>
reverse_iterator LLGL::DynamicArray< T, Allocator >::rbegin ( )
inline

◆ rbegin() [2/2]

template<typename T, typename Allocator = std::allocator<T>>
const_reverse_iterator LLGL::DynamicArray< T, Allocator >::rbegin ( ) const
inline

◆ release()

template<typename T, typename Allocator = std::allocator<T>>
pointer LLGL::DynamicArray< T, Allocator >::release ( )
inline

Release the ownership of the internally allocated memory.

Remarks
This must later be deallocated with Allocator::deallocate().

◆ rend() [1/2]

template<typename T, typename Allocator = std::allocator<T>>
reverse_iterator LLGL::DynamicArray< T, Allocator >::rend ( )
inline

◆ rend() [2/2]

template<typename T, typename Allocator = std::allocator<T>>
const_reverse_iterator LLGL::DynamicArray< T, Allocator >::rend ( ) const
inline

◆ resize() [1/2]

template<typename T, typename Allocator = std::allocator<T>>
void LLGL::DynamicArray< T, Allocator >::resize ( size_type newSize,
const value_type & value )
inline

Resizes this array to the new size if the new size is larger than the old size and explicitly initializes all newly allocated elements.

Parameters
[in]newSizeSpecifies the new array size (in number of elements).
[in]valueSpecifies the value all newly allocated elements will be initialized with.
Remarks
After this call, size() returns the same value as the input parameter size.
See also
resize(size_type)

◆ resize() [2/2]

template<typename T, typename Allocator = std::allocator<T>>
void LLGL::DynamicArray< T, Allocator >::resize ( size_type newSize,
UninitializeTag  )
inline

Resizes this array to the new size if the new size is larger than the old size. This will also leave all new elements uninitialized.

Parameters
[in]newSizeSpecifies the new array size (in number of elements).
Remarks
After this call, size() returns the same value as the input parameter size.
See also
resize(size_type, const value_type&)

◆ size()

template<typename T, typename Allocator = std::allocator<T>>
size_type LLGL::DynamicArray< T, Allocator >::size ( ) const
inlinenoexcept

Returns the size (in number of elements) of this array.

◆ swap()

template<typename T, typename Allocator = std::allocator<T>>
void LLGL::DynamicArray< T, Allocator >::swap ( DynamicArray< T, Allocator > & other)
inlinenoexcept

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