70 const T *
const list_data = std::data(l);
71 for (std::size_t i = 0; i < l.size(); ++i) {
90 array(
const std::size_t n,
const T& v) noexcept :
array(n) {
96 std::copy(d.begin(), d.end(),
begin());
107 std::copy(d.begin(), d.end(),
begin());
136 template <template <typename... Args> class container, typename... Types>
137 array(const container<Types...>& v) noexcept : array(v.size()) {
138 // assert first type in Types... is 'T'
139 static_assert(std::is_same_v<T, std::tuple_element_t<0, std::tuple<Types...>>>);
141 std::copy(v.begin(), v.end(), begin());
145 template <template <typename... Args> class container, typename... Types>
146 array& operator= (const container<Types...>& v) noexcept {
147 // assert first type in Types... is 'T'
148 static_assert(std::is_same_v<T, std::tuple_element_t<0, std::tuple<Types...>>>);
151 std::copy(v.begin(), v.end(), begin());
163 if (
size() != d.size()) {
return size() < d.size(); }
165 for (std::size_t i = 0; i <
size(); ++i) {
166 if (
m_data[i] != d.m_data[i]) {
187 void resize(
const std::size_t new_size)
noexcept {
202 void resize(
const std::size_t new_size,
const T& v)
noexcept {
215 [[nodiscard]] std::size_t
size() const noexcept {
return m_size; }
235 [[nodiscard]]
const T&
operator[] (
const std::size_t i)
const noexcept {
250 [[nodiscard]]
const T&
first() const noexcept {
257 [[nodiscard]] T&
back() noexcept {
264 [[nodiscard]]
const T&
back() const noexcept {
272 void fill(
const T& v)
noexcept {
281 [[nodiscard]] T *
at(
const std::size_t i)
noexcept {
292 [[nodiscard]] T
const *
at(
const std::size_t i)
const noexcept {
Main namespace of the library.
Definition basic_types.hpp:48
Wrapper of a C array for automatic deallocation of memory.
Definition array.hpp:59
T const * begin() const noexcept
Constant raw pointer to first element.
Definition array.hpp:305
T const * at(const std::size_t i) const noexcept
Pointer at a specific location of the array.
Definition array.hpp:292
T & first() noexcept
Non-constant reference to the first element in the array.
Definition array.hpp:243
const T & back() const noexcept
Constant reference to the first element in the array.
Definition array.hpp:264
std::size_t m_size
The size of this array in number of elements.
Definition array.hpp:320
const T & first() const noexcept
Constant reference to the first element in the array.
Definition array.hpp:250
array(const std::size_t n, const T &v) noexcept
Constructor with size.
Definition array.hpp:90
array() noexcept=default
Default constructor.
void resize(const std::size_t new_size, const T &v) noexcept
Resize-initialize the array.
Definition array.hpp:202
~array() noexcept
Destructor.
Definition array.hpp:157
void fill(const T &v) noexcept
Assign the same value to every element in the data.
Definition array.hpp:272
void alloc_data() noexcept
Definition array.hpp:312
T * begin() noexcept
Non-constant raw pointer to first element.
Definition array.hpp:300
T * end() noexcept
Non-constant raw pointer to last+1 element.
Definition array.hpp:302
T & back() noexcept
Non-constant reference to the last element in the array.
Definition array.hpp:257
std::size_t size() const noexcept
Size of the array.
Definition array.hpp:215
T & operator[](const std::size_t i) noexcept
Element at position i.
Definition array.hpp:223
void resize(const std::size_t new_size) noexcept
Resize the array.
Definition array.hpp:187
T const * end() const noexcept
Constant raw pointer to last+1 element.
Definition array.hpp:307
T * at(const std::size_t i) noexcept
Pointer at a specific location of the array.
Definition array.hpp:281
array(const array &d) noexcept
Copy constructor.
Definition array.hpp:94
void clear() noexcept
Clear the contents of the array.
Definition array.hpp:174
array & operator=(const array &d) noexcept
Copy assignment operator.
Definition array.hpp:100
array(array &&d) noexcept
Move constructor.
Definition array.hpp:113
bool operator==(const array &d) const noexcept
Comparison of equal data arrays.
Definition array.hpp:162
T * m_data
Pointer to the memory allocated by this array.
Definition array.hpp:318
array(const std::size_t n) noexcept
Constructor with size.
Definition array.hpp:82