1#ifndef JIWOO_EQUILENGTH_ARRAYS_HPP
2#define JIWOO_EQUILENGTH_ARRAYS_HPP
22template<
typename Value_>
39 my_ptr = safely_allocate(
42 [](std::size_t, Value_*) ->
void {}
52 my_ptr = safely_allocate(
55 [&](std::size_t, Value_* ptr) ->
void {
56 std::fill_n(ptr,
length, fill);
67 my_ptr = safely_allocate(
70 [&](std::size_t i, Value_* ptr) ->
void {
71 std::copy_n(other.my_ptr[i], my_length, ptr);
88 Value_** my_ptr = NULL;
89 std::size_t my_size = 0;
90 std::size_t my_length = 0;
92 template<
typename Extra_>
93 static Value_** safely_allocate(std::size_t
size, std::size_t
length, Extra_ extra) {
94 Value_** output =
new Value_* [
size];
96 std::size_t allocated = 0;
98 for (std::size_t i = 0; i <
size; ++i) {
99 output[i] =
new Value_ [
length];
104 for (std::size_t x = 0; x < allocated; ++x) {
119 if (my_ptr != NULL) {
120 for (std::size_t i = 0; i < my_size; ++i) {
139 if constexpr(std::is_nothrow_copy_assignable<Value_>::value) {
140 if (other.my_size == my_size && other.my_length == my_length) {
141 if (other.my_ptr != my_ptr) {
142 for (std::size_t i = 0; i < my_size; ++i) {
143 std::copy_n(other.my_ptr[i], my_length, my_ptr[i]);
178 std::swap(other.my_size, my_size);
179 std::swap(other.my_length, my_length);
180 std::swap(other.my_ptr, my_ptr);
234 const Value_*
const *
get()
const {
264 return my_ptr[my_size - 1];
273 return my_ptr[my_size - 1];
289 const Value_*
const*
begin()
const {
299 return my_ptr + my_size;
306 const Value_*
const*
end()
const {
307 return my_ptr + my_size;
Array of equilength arrays.
Definition EquilengthArrays.hpp:23
bool empty() const
Definition EquilengthArrays.hpp:201
const Value_ * back() const
Definition EquilengthArrays.hpp:272
Value_ * front()
Definition EquilengthArrays.hpp:244
EquilengthArrays & operator=(EquilengthArrays &&other) noexcept
Definition EquilengthArrays.hpp:166
Value_ *const * begin()
Definition EquilengthArrays.hpp:281
EquilengthArrays(std::size_t size, std::size_t length, Value_ fill)
Definition EquilengthArrays.hpp:51
EquilengthArrays(std::size_t size, std::size_t length)
Definition EquilengthArrays.hpp:38
const Value_ * operator[](std::size_t i) const
Definition EquilengthArrays.hpp:219
Value_ *const * get()
Definition EquilengthArrays.hpp:227
std::size_t length() const
Definition EquilengthArrays.hpp:194
const Value_ *const * end() const
Definition EquilengthArrays.hpp:306
EquilengthArrays & operator=(const EquilengthArrays &other)
Definition EquilengthArrays.hpp:135
const Value_ *const * begin() const
Definition EquilengthArrays.hpp:289
Value_ *const * end()
Definition EquilengthArrays.hpp:298
const Value_ * front() const
Definition EquilengthArrays.hpp:253
std::size_t size() const
Definition EquilengthArrays.hpp:187
Value_ * back()
Definition EquilengthArrays.hpp:263
~EquilengthArrays()
Definition EquilengthArrays.hpp:118
EquilengthArrays()=default
Value_ * operator[](std::size_t i)
Definition EquilengthArrays.hpp:210
void swap(EquilengthArrays &other) noexcept
Definition EquilengthArrays.hpp:177
const Value_ *const * get() const
Definition EquilengthArrays.hpp:234
EquilengthArrays(const EquilengthArrays &other)
Definition EquilengthArrays.hpp:66
EquilengthArrays(EquilengthArrays &&other) noexcept
Definition EquilengthArrays.hpp:82
Automatic memory management of array pointers.
Definition EquilengthArrays.hpp:13