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

A dynamically alloacted array of trivial types. More...

#include <trivial_array.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_array () noexcept
 Construct the array with a default constructed allocator. More...
 
 trivial_array (const Alloc &allocator) noexcept
 Construct the array with the given allocator. More...
 
 trivial_array (size_t n, const Alloc &allocator=Alloc())
 Construct the array with the given allocator and size. More...
 
 trivial_array (size_t n, const T &value, const Alloc &allocator=Alloc())
 Construct the array with the given allocator, size and default value. More...
 
 trivial_array (std::initializer_list< T > initializer, const Alloc &allocator=Alloc())
 Construct the array with the allocator and range of values. More...
 
 trivial_array (const T *first, const T *last, const Alloc &allocator=Alloc())
 Construct the array with the allocator and range of values. More...
 
 trivial_array (const trivial_array &other) noexcept
 
 trivial_array (trivial_array &&other) noexcept
 
 trivial_array (const trivial_array &other, const Alloc &allocator) noexcept
 
 trivial_array (trivial_array &&other, const Alloc &allocator) noexcept
 
 ~trivial_array () noexcept
 
trivial_arrayoperator= (const trivial_array &other) noexcept
 
trivial_arrayoperator= (trivial_array &&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
 
std::reverse_iterator< T * > rbegin () noexcept
 
std::reverse_iterator< const T * > rbegin () const noexcept
 
std::reverse_iterator< T * > rend () noexcept
 
std::reverse_iterator< const T * > rend () const noexcept
 
size_t size () const noexcept
 Returns the current size of the array. More...
 
bool empty () const noexcept
 Returns true if the array has been initialized with no size. More...
 
iterator data () noexcept
 Returns an iterator to the start of the array. More...
 
const_iterator data () const noexcept
 Returns a const iterator to the start of the array. More...
 
T & at (size_t index) const noexcept
 Returns a reference to the element at index. More...
 
void resize (size_t n)
 Resizes the array to the given size. More...
 
void assign (const T *first, const T *last)
 Assigns the given values from first to last. It also resizes if the size doesn't match the number of elements. More...
 

Detailed Description

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

A dynamically alloacted array of 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_array< T, Alloc >::const_iterator

◆ const_reverse_iterator

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

◆ iterator

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

◆ reverse_iterator

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

Constructor & Destructor Documentation

◆ trivial_array() [1/10]

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

Construct the array with a default constructed allocator.

◆ trivial_array() [2/10]

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

Construct the array with the given allocator.

Parameters
allocatorThe allocator to use

◆ trivial_array() [3/10]

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

Construct the array with the given allocator and size.

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

◆ trivial_array() [4/10]

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

Construct the array with the given allocator, size and default value.

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

◆ trivial_array() [5/10]

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

Construct the array with the allocator and range of values.

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

◆ trivial_array() [6/10]

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

Construct the array 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_array() [7/10]

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

◆ trivial_array() [8/10]

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

◆ trivial_array() [9/10]

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

◆ trivial_array() [10/10]

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

◆ ~trivial_array()

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

Member Function Documentation

◆ assign()

template<typename T , typename Alloc >
void ktl::trivial_array< T, Alloc >::assign ( const T *  first,
const T *  last 
)
inline

Assigns the given values from first to last. It also resizes if the size doesn't match the number of elements.

Parameters
firstA pointer to the first element.
lastA pointer one element past the last element.

◆ at()

template<typename T , typename Alloc >
T& ktl::trivial_array< 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 array. 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_array< T, Alloc >::begin ( ) const
inlinenoexcept

◆ begin() [2/2]

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

◆ data() [1/2]

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

Returns a const iterator to the start of the array.

Returns
A const iterator to the start of the array.

◆ data() [2/2]

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

Returns an iterator to the start of the array.

Returns
An iterator to the start of the array.

◆ empty()

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

Returns true if the array has been initialized with no size.

Returns
Whether the array has a size of 0.

◆ end() [1/2]

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

◆ end() [2/2]

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

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ operator[]() [1/2]

template<typename T , typename Alloc >
const T& ktl::trivial_array< 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_array< 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.

◆ rbegin() [1/2]

template<typename T , typename Alloc >
std::reverse_iterator<const T*> ktl::trivial_array< T, Alloc >::rbegin ( ) const
inlinenoexcept

◆ rbegin() [2/2]

template<typename T , typename Alloc >
std::reverse_iterator<T*> ktl::trivial_array< T, Alloc >::rbegin ( )
inlinenoexcept

◆ rend() [1/2]

template<typename T , typename Alloc >
std::reverse_iterator<const T*> ktl::trivial_array< T, Alloc >::rend ( ) const
inlinenoexcept

◆ rend() [2/2]

template<typename T , typename Alloc >
std::reverse_iterator<T*> ktl::trivial_array< T, Alloc >::rend ( )
inlinenoexcept

◆ resize()

template<typename T , typename Alloc >
void ktl::trivial_array< T, Alloc >::resize ( size_t  n)
inline

Resizes the array to the given size.

Parameters
nThe size to resize to.

◆ size()

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

Returns the current size of the array.

Returns
The size of the array in number of elements.

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