mirror of https://github.com/AxioDL/metaforce.git
Add trivial destructor condition to reserved_vector
This commit is contained in:
parent
41032d0a7c
commit
285669db05
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <type_traits>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "optional.hpp"
|
#include "optional.hpp"
|
||||||
#include <logvisor/logvisor.hpp>
|
#include <logvisor/logvisor.hpp>
|
||||||
|
@ -182,8 +183,9 @@ public:
|
||||||
reserved_vector() : base(0) {}
|
reserved_vector() : base(0) {}
|
||||||
~reserved_vector()
|
~reserved_vector()
|
||||||
{
|
{
|
||||||
for (size_t i=0 ; i<base::x0_size ; ++i)
|
if (std::is_destructible<T>::value && !std::is_trivially_destructible<T>::value)
|
||||||
base::_value(i).~T();
|
for (size_t i=0 ; i<base::x0_size ; ++i)
|
||||||
|
base::_value(i).~T();
|
||||||
}
|
}
|
||||||
|
|
||||||
void push_back(const T& d)
|
void push_back(const T& d)
|
||||||
|
@ -224,7 +226,8 @@ public:
|
||||||
Log.report(logvisor::Fatal, "pop_back() called on empty rstl::reserved_vector.");
|
Log.report(logvisor::Fatal, "pop_back() called on empty rstl::reserved_vector.");
|
||||||
#endif
|
#endif
|
||||||
--base::x0_size;
|
--base::x0_size;
|
||||||
base::_value(base::x0_size).~T();
|
if (std::is_destructible<T>::value && !std::is_trivially_destructible<T>::value)
|
||||||
|
base::_value(base::x0_size).~T();
|
||||||
}
|
}
|
||||||
|
|
||||||
iterator insert(const_iterator pos, const T& value)
|
iterator insert(const_iterator pos, const T& value)
|
||||||
|
@ -287,8 +290,9 @@ public:
|
||||||
}
|
}
|
||||||
else if (size < base::x0_size)
|
else if (size < base::x0_size)
|
||||||
{
|
{
|
||||||
for (size_t i = size; i < base::x0_size; ++i)
|
if (std::is_destructible<T>::value && !std::is_trivially_destructible<T>::value)
|
||||||
base::_value(i).~T();
|
for (size_t i = size; i < base::x0_size; ++i)
|
||||||
|
base::_value(i).~T();
|
||||||
base::x0_size = size;
|
base::x0_size = size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -307,8 +311,9 @@ public:
|
||||||
}
|
}
|
||||||
else if (size < base::x0_size)
|
else if (size < base::x0_size)
|
||||||
{
|
{
|
||||||
for (size_t i = size; i < base::x0_size; ++i)
|
if (std::is_destructible<T>::value && !std::is_trivially_destructible<T>::value)
|
||||||
base::_value(i).~T();
|
for (size_t i = size; i < base::x0_size; ++i)
|
||||||
|
base::_value(i).~T();
|
||||||
base::x0_size = size;
|
base::x0_size = size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -322,14 +327,16 @@ public:
|
||||||
for (auto it = base::_const_cast_iterator(pos) + 1; it != base::end(); ++it)
|
for (auto it = base::_const_cast_iterator(pos) + 1; it != base::end(); ++it)
|
||||||
*(it - 1) = std::forward<T>(*it);
|
*(it - 1) = std::forward<T>(*it);
|
||||||
--base::x0_size;
|
--base::x0_size;
|
||||||
base::_value(base::x0_size).~T();
|
if (std::is_destructible<T>::value && !std::is_trivially_destructible<T>::value)
|
||||||
|
base::_value(base::x0_size).~T();
|
||||||
return base::_const_cast_iterator(pos);
|
return base::_const_cast_iterator(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
for (auto it = base::begin(); it != base::end(); ++it)
|
if (std::is_destructible<T>::value && !std::is_trivially_destructible<T>::value)
|
||||||
it->~T();
|
for (auto it = base::begin(); it != base::end(); ++it)
|
||||||
|
it->~T();
|
||||||
base::x0_size = 0;
|
base::x0_size = 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -347,8 +354,9 @@ class prereserved_vector : public _reserved_vector_base<T, N>
|
||||||
}
|
}
|
||||||
void _deinit()
|
void _deinit()
|
||||||
{
|
{
|
||||||
for (auto& i : base::x4_data)
|
if (std::is_destructible<T>::value && !std::is_trivially_destructible<T>::value)
|
||||||
reinterpret_cast<T*>(std::addressof(i))->~T();
|
for (auto& i : base::x4_data)
|
||||||
|
reinterpret_cast<T*>(std::addressof(i))->~T();
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
using base = _reserved_vector_base<T, N>;
|
using base = _reserved_vector_base<T, N>;
|
||||||
|
|
Loading…
Reference in New Issue