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

The ConstArray class provides functionality similar to std::vector, except that it does not construct or destruct elements, does not allow insertions or appending, and can use memory it does not own for storage. 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 <ConstArray.hpp>

Public Member Functions

 ConstArray ()
 Create an empty non mutable array.
 
 ConstArray (Array< T > array)
 Create a new non-mutable array with a default value for each element. More...
 
 ConstArray (T const *const ptr, size_t const size)
 Create a new non-owning array. If the pointer is null, then size must 0. More...
 
 ConstArray (std::unique_ptr< T[]> &&ptr, size_t const size)
 Create a new constant array. More...
 
 ConstArray (ConstArray &&rhs) noexcept
 Move constructor. More...
 
 ConstArray (ConstArray const &rhs)=delete
 Deleted copy-assignment operator. More...
 
ConstArrayoperator= (ConstArray const &rhs)=delete
 Deleted assignment operator. More...
 
ConstArrayoperator= (ConstArray &&lhs)
 Assignment operator (move). More...
 
 ~ConstArray ()
 Destructor.
 
T const & operator[] (size_t const index) const noexcept
 Get the element at the given index. 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...
 
T const * begin () const noexcept
 Get the beginning iterator. More...
 
T const * end () const noexcept
 Get the end iterator. More...
 
T const & front () const noexcept
 Get the front of the array. More...
 
T const & back () const noexcept
 Get the back of the array. More...
 
void clear ()
 Free the memory associated with this array.
 

Detailed Description

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

The ConstArray class provides functionality similar to std::vector, except that it does not construct or destruct elements, does not allow insertions or appending, and can use memory it does not own for storage. 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

◆ ConstArray() [1/5]

template<typename T >
sl::ConstArray< T >::ConstArray ( Array< T >  array)
inline

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

Parameters
sizeThe size of the array.

◆ ConstArray() [2/5]

template<typename T >
sl::ConstArray< T >::ConstArray ( T const *const  ptr,
size_t const  size 
)
inline

Create a new non-owning array. If the pointer is null, then size must 0.

Parameters
ptrThe pointer.
sizeThe number of elements in the array.

◆ ConstArray() [3/5]

template<typename T >
sl::ConstArray< T >::ConstArray ( std::unique_ptr< T[]> &&  ptr,
size_t const  size 
)
inline

Create a new constant array.

Parameters
ptrThe data to move into the array.
sizeThe size of the array.

◆ ConstArray() [4/5]

template<typename T >
sl::ConstArray< T >::ConstArray ( ConstArray< T > &&  rhs)
inlinenoexcept

Move constructor.

Parameters
rhsThe array to move.

◆ ConstArray() [5/5]

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

Deleted copy-assignment operator.

Parameters
rhsThe ConstArray to copy.

Member Function Documentation

◆ back()

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

Get the back of the array.

Returns
The last element.

◆ begin()

template<typename T >
T const* sl::ConstArray< T >::begin ( ) const
inlinenoexcept

Get the beginning iterator.

Returns
The iterator/pointer.

◆ data()

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

Get the underlying memory.

Returns
The underlying memory.

◆ end()

template<typename T >
T const* sl::ConstArray< T >::end ( ) const
inlinenoexcept

Get the end iterator.

Returns
The iterator/pointer.

◆ front()

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

Get the front of the array.

Returns
The first element.

◆ operator=() [1/2]

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

Deleted assignment operator.

Parameters
lhsThe ConstArray to copy.
Returns
This array.

◆ operator=() [2/2]

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

Assignment operator (move).

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

◆ operator[]()

template<typename T >
T const& sl::ConstArray< 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.

◆ size()

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

Get the size of the underlying memory allocation.

Returns
The size of the memory allocation.

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