12#ifndef _TPF_MATRIX_HPP
13#define _TPF_MATRIX_HPP
20 #if _MSVC_LANG < 201703L
21 #error This libary requires C++17 Standard (Visual Studio 2017).
25 #if __cplusplus < 201703
26 #error This library requires C++17 Standard (GNU g++ version 8.0 or clang++ version 8.0 above)
48 template<
typename ElementType>
68 if constexpr (std::is_pod_v<ElementType>)
69 _aligned_free(this->m_ptr);
71 delete[] this-> m_ptr;
73 this->m_ptr =
nullptr;
79 this->m_ptr =
nullptr;
82 ElementType* new_alloc()
86 if constexpr(std::is_pod_v<ElementType>)
88 ptr = (ElementType*) _aligned_malloc(
sizeof(ElementType) * this->m_size, 16);
94 ptr =
new ElementType[this->m_size];
96 catch(
const std::bad_alloc&)
117 return (this->m_ptr + this->m_size);
136 return std::reverse_iterator(
end());
141 return std::reverse_iterator(
begin());
146 return std::reverse_iterator(
cend());
151 return std::reverse_iterator(
cbegin());
154 size_t size()
const {
return this->m_size; }
159 if(
count == this->m_size)
165 this->m_size =
count;
166 this->m_ptr = new_alloc();
179 this->m_ptr = new_alloc();
188 m_size{right_hand_side.m_size}
190 this->m_ptr = new_alloc();
195 if constexpr(std::is_pod_v<ElementType>)
196 std::memcpy(this->m_ptr, right_hand_side.m_ptr, m_size *
sizeof(ElementType));
199 for(
size_t i = 0; i < this->m_size; ++i)
200 this->m_ptr[i] = right_hand_side.m_ptr[i];
206 ElementType &
operator[](
size_t index) {
return this->m_ptr[index]; }
208 const ElementType &
operator[](
size_t index)
const {
return this->m_ptr[index]; }
210 ElementType &
at(
size_t index)
212 if (index < this->m_size && this->m_ptr)
213 return this->m_ptr[index];
218 const ElementType &
at(
size_t index)
const
220 if (index < this->m_size && this->m_ptr)
221 return this->m_ptr[index];
235 if (
this != std::addressof(right_hand_side))
237 if (this->m_size == right_hand_side.m_size)
243 if constexpr(std::is_pod_v<ElementType>)
244 std::memcpy(this->m_ptr, right_hand_side.m_ptr, m_size *
sizeof(ElementType));
247 for(
size_t i = 0; i < this->m_size; ++i)
248 this->m_ptr[i] = right_hand_side.m_ptr[i];
255 this->m_size = right_hand_side.m_size;
257 this->m_ptr = new_alloc();
262 if constexpr(std::is_pod_v<ElementType>)
263 std::memcpy(this->m_ptr, right_hand_side.m_ptr, m_size *
sizeof(ElementType));
266 for(
size_t i = 0; i < this->m_size; ++i)
267 this->m_ptr[i] = right_hand_side.m_ptr[i];
276 : m_size{right_hand_side.m_size},
277 m_ptr{right_hand_side.m_ptr}
282 right_hand_side.invalidate();
287 if (
this != std::addressof(right_hand_side))
291 this->m_size = right_hand_side.m_size;
292 this->m_ptr = right_hand_side.m_ptr;
297 right_hand_side.invalidate();
313 for(
size_t i = 0; i <
size; ++i)
316 os << da[
size] <<
" }";
const ElementType & at(size_t index) const
ElementType & operator[](size_t index)
ElementType & at(size_t index)
ElementType * operator&()
dynamic_array & operator=(const dynamic_array &right_hand_side)
const ElementType * const_iterator
void resize(size_t count)
dynamic_array & operator=(dynamic_array &&right_hand_side) noexcept
dynamic_array(const dynamic_array &right_hand_side)
friend std::ostream & operator<<(std::ostream &os, const dynamic_array &da)
dynamic_array(dynamic_array &&right_hand_side) noexcept
const ElementType & operator[](size_t index) const
dynamic_array(size_t size=1)
Includes subnamespace conversion.
#define Tpf_ThrowDebugException(debug_message)
Throw a debug_exception with message as argument.