overhauled physics engine
This commit is contained in:
@@ -156,7 +156,8 @@ public:
|
||||
assert(_data != nullptr);
|
||||
std::uninitialized_copy(init.begin(), init.end(), begin());
|
||||
}
|
||||
Array(const Array &other)
|
||||
|
||||
constexpr Array(const Array &other)
|
||||
: arraySize(other.arraySize)
|
||||
, allocated(other.allocated)
|
||||
, allocator(std::allocator_traits<allocator_type>::select_on_container_copy_construction(other.allocator))
|
||||
@@ -165,7 +166,16 @@ public:
|
||||
assert(_data != nullptr);
|
||||
std::uninitialized_copy(other.begin(), other.end(), begin());
|
||||
}
|
||||
Array(Array &&other) noexcept
|
||||
constexpr Array(const Array& other, const Allocator& alloc)
|
||||
: arraySize(other.arraySize)
|
||||
, allocated(other.allocated)
|
||||
, allocator(alloc)
|
||||
{
|
||||
_data = allocateArray(other.allocated);
|
||||
assert(_data != nullptr);
|
||||
std::uninitialized_copy(other.begin(), other.end(), begin());
|
||||
}
|
||||
constexpr Array(Array &&other) noexcept
|
||||
: arraySize(std::move(other.arraySize))
|
||||
, allocated(std::move(other.allocated))
|
||||
, allocator(std::move(other.allocator))
|
||||
@@ -175,10 +185,26 @@ public:
|
||||
other.allocated = 0;
|
||||
other.arraySize = 0;
|
||||
}
|
||||
constexpr Array(Array &&other, const Allocator& alloc) noexcept
|
||||
: arraySize(std::move(other.arraySize))
|
||||
, allocated(std::move(other.allocated))
|
||||
, allocator(alloc)
|
||||
{
|
||||
_data = allocateArray(other.allocated);
|
||||
std::uninitialized_move(other.begin(), other.end(), begin());
|
||||
other.deallocateArray(other._data, other.allocated);
|
||||
other._data = nullptr;
|
||||
other.allocated = 0;
|
||||
other.arraySize = 0;
|
||||
}
|
||||
Array &operator=(const Array &other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
if (other.arraySize > allocated)
|
||||
{
|
||||
clear();
|
||||
}
|
||||
if constexpr (std::allocator_traits<allocator_type>::propagate_on_container_copy_assignment::value )
|
||||
{
|
||||
if (!std::allocator_traits<allocator_type>::is_always_equal::value
|
||||
@@ -188,10 +214,6 @@ public:
|
||||
}
|
||||
allocator = other.allocator;
|
||||
}
|
||||
if (other.arraySize > allocated)
|
||||
{
|
||||
clear();
|
||||
}
|
||||
if(_data == nullptr)
|
||||
{
|
||||
_data = allocateArray(other.allocated);
|
||||
@@ -207,14 +229,14 @@ public:
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
if constexpr (std::allocator_traits<allocator_type>::propagate_on_container_move_assignment::value)
|
||||
{
|
||||
allocator = std::move(other.allocator);
|
||||
}
|
||||
if (_data != nullptr)
|
||||
{
|
||||
clear();
|
||||
}
|
||||
if constexpr (std::allocator_traits<allocator_type>::propagate_on_container_move_assignment::value)
|
||||
{
|
||||
allocator = std::move(other.allocator);
|
||||
}
|
||||
allocated = std::move(other.allocated);
|
||||
arraySize = std::move(other.arraySize);
|
||||
_data = other._data;
|
||||
@@ -395,7 +417,7 @@ public:
|
||||
}
|
||||
constexpr void resize(size_type newSize)
|
||||
{
|
||||
resizeInternal(newSize, std::move(T()));
|
||||
resizeInternal(newSize, T());
|
||||
}
|
||||
constexpr void resize(size_type newSize, const value_type& value)
|
||||
{
|
||||
@@ -532,7 +554,7 @@ private:
|
||||
return _data[arraySize - 1];
|
||||
}
|
||||
template<typename Type>
|
||||
void resizeInternal(size_type newSize, Type&& value) noexcept
|
||||
void resizeInternal(size_type newSize, const Type& value) noexcept
|
||||
{
|
||||
if (newSize <= allocated)
|
||||
{
|
||||
@@ -550,7 +572,7 @@ private:
|
||||
// Or construct the new elements by default
|
||||
for(size_type i = arraySize; i < newSize; ++i)
|
||||
{
|
||||
std::allocator_traits<allocator_type>::construct(allocator, &_data[i], std::move(value));
|
||||
std::allocator_traits<allocator_type>::construct(allocator, &_data[i], value);
|
||||
}
|
||||
}
|
||||
arraySize = newSize;
|
||||
@@ -568,7 +590,7 @@ private:
|
||||
// As well as default initialize the others
|
||||
for(size_type i = arraySize; i < newSize; ++i)
|
||||
{
|
||||
std::allocator_traits<allocator_type>::construct(allocator, &newData[i], std::move(value));
|
||||
std::allocator_traits<allocator_type>::construct(allocator, &newData[i], value);
|
||||
}
|
||||
deallocateArray(_data, allocated);
|
||||
arraySize = newSize;
|
||||
|
||||
@@ -124,10 +124,46 @@ public:
|
||||
, beginIt(Iterator(root))
|
||||
, endIt(Iterator(tail))
|
||||
, _size(0)
|
||||
, allocator(NodeAllocator())
|
||||
, allocator(Allocator())
|
||||
{
|
||||
}
|
||||
explicit List(const Allocator& alloc)
|
||||
: root(nullptr)
|
||||
, tail(nullptr)
|
||||
, beginIt(Iterator(root))
|
||||
, endIt(Iterator(tail))
|
||||
, _size(0)
|
||||
, allocator(alloc)
|
||||
{
|
||||
}
|
||||
List(size_type count, const T& value = T(), const Allocator& alloc = Allocator())
|
||||
: List(alloc)
|
||||
{
|
||||
for(size_type i = 0; i < count; ++i)
|
||||
{
|
||||
add(value);
|
||||
}
|
||||
}
|
||||
List(size_type count, const Allocator& alloc = Allocator())
|
||||
: List(alloc)
|
||||
{
|
||||
for(size_type i = 0; i < count; ++i)
|
||||
{
|
||||
add(T());
|
||||
}
|
||||
}
|
||||
List(const List& other)
|
||||
: List(std::allocator_traits<allocator_type>::select_on_container_copy_construction(other.allocator))
|
||||
{
|
||||
//TODO: improve
|
||||
for(const auto& it : other)
|
||||
{
|
||||
add(it);
|
||||
}
|
||||
}
|
||||
|
||||
List(const List& other, const Allocator& alloc)
|
||||
: List(alloc)
|
||||
{
|
||||
//TODO: improve
|
||||
for(const auto& it : other)
|
||||
@@ -141,8 +177,19 @@ public:
|
||||
, beginIt(std::move(other.beginIt))
|
||||
, endIt(std::move(other.endIt))
|
||||
, _size(std::move(other._size))
|
||||
, allocator(std::move(other.allocator))
|
||||
{
|
||||
other._size = 0;
|
||||
other.clear();
|
||||
}
|
||||
List(List&& other, const Allocator& alloc)
|
||||
: root(std::move(other.root))
|
||||
, tail(std::move(other.tail))
|
||||
, beginIt(std::move(other.beginIt))
|
||||
, endIt(std::move(other.endIt))
|
||||
, _size(std::move(other._size))
|
||||
, allocator(allocator)
|
||||
{
|
||||
other.clear();
|
||||
}
|
||||
~List()
|
||||
{
|
||||
@@ -153,6 +200,15 @@ public:
|
||||
if(this != &other)
|
||||
{
|
||||
clear();
|
||||
if constexpr (std::allocator_traits<allocator_type>::propagate_on_container_copy_assignment::value )
|
||||
{
|
||||
if (!std::allocator_traits<allocator_type>::is_always_equal::value
|
||||
&& allocator != other.allocator)
|
||||
{
|
||||
clear();
|
||||
}
|
||||
allocator = other.allocator;
|
||||
}
|
||||
for(const auto& it : other)
|
||||
{
|
||||
add(it);
|
||||
@@ -166,6 +222,10 @@ public:
|
||||
if(this != &other)
|
||||
{
|
||||
clear();
|
||||
if constexpr (std::allocator_traits<allocator_type>::propagate_on_container_move_assignment::value)
|
||||
{
|
||||
allocator = std::move(other.allocator);
|
||||
}
|
||||
root = other.root;
|
||||
tail = other.tail;
|
||||
beginIt = other.beginIt;
|
||||
@@ -214,7 +274,7 @@ public:
|
||||
}
|
||||
// takes all elements from other and move-inserts them into
|
||||
// this, clearing other in the process
|
||||
void moveElements(List& other)
|
||||
void moveElements(List&& other)
|
||||
{
|
||||
tail->prev->next = other.root;
|
||||
other.root->prev = tail->prev;
|
||||
|
||||
Reference in New Issue
Block a user