31 #ifndef SOLIDUTILS_INCLUDE_ARRAY_HPP 32 #define SOLIDUTILS_INCLUDE_ARRAY_HPP 57 using const_iterator = T
const *;
95 std::fill(m_data.get(), m_data.get()+m_size, value);
105 Array && lhs) noexcept :
107 m_data(std::move(lhs.m_data))
119 Array const & rhs) =
delete;
130 Array const & rhs) =
delete;
144 m_data = std::move(lhs.m_data);
158 T
const val) noexcept
160 for (
size_t i = 0; i < m_size; ++i) {
174 size_t const index) noexcept
176 ASSERT_LESS(index, m_size);
177 return m_data[index];
189 size_t const index)
const noexcept
191 ASSERT_LESS(index, m_size);
192 return m_data[index];
212 T
const *
data() const noexcept
234 const_iterator
begin() const noexcept
245 const_iterator
end() const noexcept
247 return m_data.get() + m_size;
269 return m_data.get() + m_size;
300 T
const &
back() const noexcept
302 return (*
this)[m_size-1];
313 return (*
this)[m_size-1];
328 if (smallerSize < m_size) {
329 m_size = smallerSize;
339 std::unique_ptr<T[]>
steal() noexcept
342 return std::unique_ptr<T[]>(std::move(m_data));
358 std::unique_ptr<T[]> m_data;
T const & front() const noexcept
Get the front of the array.
Definition: Array.hpp:278
Array()
Default constructor, creating an empty array. This is only useful for reserve stack space in order to...
Definition: Array.hpp:63
T & back() noexcept
Get the back of the array.
Definition: Array.hpp:311
Array(size_t const size)
Create a new mutable array.
Definition: Array.hpp:76
const_iterator begin() const noexcept
Get the beginning iterator.
Definition: Array.hpp:234
T * data() noexcept
Get the underlying memory.
Definition: Array.hpp:201
void clear()
Free the memory associated with this array.
Definition: Array.hpp:349
iterator end() noexcept
Get the end iterator (mutable).
Definition: Array.hpp:267
T const & back() const noexcept
Get the back of the array.
Definition: Array.hpp:300
size_t size() const noexcept
Get the size of the underlying memory allocation.
Definition: Array.hpp:223
T & operator[](size_t const index) noexcept
Get the element at the given index.
Definition: Array.hpp:173
Array(Array &&lhs) noexcept
Move constructor.
Definition: Array.hpp:104
iterator begin() noexcept
Get the beginning iterator (mutable).
Definition: Array.hpp:256
Array(size_t const size, T const value)
Create a new mutable array with a default value for each element.
Definition: Array.hpp:90
const_iterator end() const noexcept
Get the end iterator.
Definition: Array.hpp:245
T & front() noexcept
Get the front of the array.
Definition: Array.hpp:289
T const & operator[](size_t const index) const noexcept
Get the element at the given index.
Definition: Array.hpp:188
The Array class provides functionality similar to std::vector, except that it does not construct or d...
Definition: Array.hpp:53
T const * data() const noexcept
Get the underlying memory.
Definition: Array.hpp:212
Array & operator=(Array &&lhs)
Assignment operator (move).
Definition: Array.hpp:140
std::unique_ptr< T[]> steal() noexcept
Pull out the heap memory from this Array, leaving it empty.
Definition: Array.hpp:339
Array & operator=(Array const &rhs)=delete
Deleted assignment operator.
void shrink(size_t smallerSize)
Shrink the size of the array. This does not gaurantee the memory allocation will be decreased...
Definition: Array.hpp:325