SolidUtils
Public Types | Public Member Functions | List of all members
sl::Array< T > Class Template Reference

The Array class provides functionality similar to std::vector, except that it does not construct or destruct elements, and does not allow insertions or append. This is for performance reasons when initialization is not required. However, this makes it unsuitable for anything other than primitive datatypes or other structures movemable with a simple memcpy(). More...

#include <Array.hpp>

Public Types

using iterator = T *
 
using const_iterator = T const *
 

Public Member Functions

 Array ()
 Default constructor, creating an empty array. This is only useful for reserve stack space in order to re-assign.
 
 Array (size_t const size)
 Create a new mutable array. More...
 
 Array (size_t const size, T const value)
 Create a new mutable array with a default value for each element. More...
 
 Array (Array &&lhs) noexcept
 Move constructor. More...
 
 Array (Array const &rhs)=delete
 Deleted copy-assignment operator. More...
 
Arrayoperator= (Array const &rhs)=delete
 Deleted assignment operator. More...
 
Arrayoperator= (Array &&lhs)
 Assignment operator (move). More...
 
void set (T const val) noexcept
 Set all entries in the array to the given value. More...
 
T & operator[] (size_t const index) noexcept
 Get the element at the given index. More...
 
T const & operator[] (size_t const index) const noexcept
 Get the element at the given index. More...
 
T * data () noexcept
 Get the underlying memory. More...
 
T const * data () const noexcept
 Get the underlying memory. More...
 
size_t size () const noexcept
 Get the size of the underlying memory allocation. More...
 
const_iterator begin () const noexcept
 Get the beginning iterator. More...
 
const_iterator end () const noexcept
 Get the end iterator. More...
 
iterator begin () noexcept
 Get the beginning iterator (mutable). More...
 
iterator end () noexcept
 Get the end iterator (mutable). More...
 
T const & front () const noexcept
 Get the front of the array. More...
 
T & front () noexcept
 Get the front of the array. More...
 
T const & back () const noexcept
 Get the back of the array. More...
 
T & back () noexcept
 Get the back of the array. More...
 
void shrink (size_t smallerSize)
 Shrink the size of the array. This does not gaurantee the memory allocation will be decreased, but only that the local size of the array will shrink. Calling this method with a smallerSize greater than the size of the array will have no effect. More...
 
std::unique_ptr< T[]> steal () noexcept
 Pull out the heap memory from this Array, leaving it empty. More...
 
void clear ()
 Free the memory associated with this array.
 

Detailed Description

template<typename T>
class sl::Array< T >

The Array class provides functionality similar to std::vector, except that it does not construct or destruct elements, and does not allow insertions or append. This is for performance reasons when initialization is not required. However, this makes it unsuitable for anything other than primitive datatypes or other structures movemable with a simple memcpy().

Template Parameters
TThe type of element.

Constructor & Destructor Documentation

◆ Array() [1/4]

template<typename T>
sl::Array< T >::Array ( size_t const  size)
inline

Create a new mutable array.

Parameters
sizeThe size of the array.

◆ Array() [2/4]

template<typename T>
sl::Array< T >::Array ( size_t const  size,
T const  value 
)
inline

Create a new mutable array with a default value for each element.

Parameters
sizeThe size of the array.

◆ Array() [3/4]

template<typename T>
sl::Array< T >::Array ( Array< T > &&  lhs)
inlinenoexcept

Move constructor.

Parameters
lhsThe array to move.

◆ Array() [4/4]

template<typename T>
sl::Array< T >::Array ( Array< T > const &  rhs)
delete

Deleted copy-assignment operator.

Parameters
rhsThe Array to copy.

Member Function Documentation

◆ back() [1/2]

template<typename T>
T const& sl::Array< T >::back ( ) const
inlinenoexcept

Get the back of the array.

Returns
The last element.

◆ back() [2/2]

template<typename T>
T& sl::Array< T >::back ( )
inlinenoexcept

Get the back of the array.

Returns
The last element.

◆ begin() [1/2]

template<typename T>
const_iterator sl::Array< T >::begin ( ) const
inlinenoexcept

Get the beginning iterator.

Returns
The iterator/pointer.

◆ begin() [2/2]

template<typename T>
iterator sl::Array< T >::begin ( )
inlinenoexcept

Get the beginning iterator (mutable).

Returns
The iterator/pointer.

◆ data() [1/2]

template<typename T>
T* sl::Array< T >::data ( )
inlinenoexcept

Get the underlying memory.

Returns
The underlying memory.

◆ data() [2/2]

template<typename T>
T const* sl::Array< T >::data ( ) const
inlinenoexcept

Get the underlying memory.

Returns
The underlying memory.

◆ end() [1/2]

template<typename T>
const_iterator sl::Array< T >::end ( ) const
inlinenoexcept

Get the end iterator.

Returns
The iterator/pointer.

◆ end() [2/2]

template<typename T>
iterator sl::Array< T >::end ( )
inlinenoexcept

Get the end iterator (mutable).

Returns
The iterator/pointer.

◆ front() [1/2]

template<typename T>
T const& sl::Array< T >::front ( ) const
inlinenoexcept

Get the front of the array.

Returns
The first element.

◆ front() [2/2]

template<typename T>
T& sl::Array< T >::front ( )
inlinenoexcept

Get the front of the array.

Returns
The first element.

◆ operator=() [1/2]

template<typename T>
Array& sl::Array< T >::operator= ( Array< T > const &  rhs)
delete

Deleted assignment operator.

Parameters
lhsThe Array to copy.
Returns
This array.

◆ operator=() [2/2]

template<typename T>
Array& sl::Array< T >::operator= ( Array< T > &&  lhs)
inline

Assignment operator (move).

Parameters
lhsThe array to assign (and destroy) to this one.
Returns
This array.

◆ operator[]() [1/2]

template<typename T>
T& sl::Array< T >::operator[] ( size_t const  index)
inlinenoexcept

Get the element at the given index.

Parameters
indexThe index of the element.
Returns
A reference to the element.

◆ operator[]() [2/2]

template<typename T>
T const& sl::Array< T >::operator[] ( size_t const  index) const
inlinenoexcept

Get the element at the given index.

Parameters
indexThe index of the element.
Returns
A reference to the element.

◆ set()

template<typename T>
void sl::Array< T >::set ( T const  val)
inlinenoexcept

Set all entries in the array to the given value.

Parameters
valThe value to set.

◆ shrink()

template<typename T>
void sl::Array< T >::shrink ( size_t  smallerSize)
inline

Shrink the size of the array. This does not gaurantee the memory allocation will be decreased, but only that the local size of the array will shrink. Calling this method with a smallerSize greater than the size of the array will have no effect.

Parameters
smallerSizeThe size to shrink the array to.

◆ size()

template<typename T>
size_t sl::Array< T >::size ( ) const
inlinenoexcept

Get the size of the underlying memory allocation.

Returns
The size of the memory allocation.

◆ steal()

template<typename T>
std::unique_ptr<T[]> sl::Array< T >::steal ( )
inlinenoexcept

Pull out the heap memory from this Array, leaving it empty.

Returns
The unique pointer to the heap memory.

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