[ox/std] Fix some Vector constexpr problems

This commit is contained in:
Gary Talent 2024-04-09 23:46:12 -05:00
parent 5eec9085f8
commit 79b42e1df7

View File

@ -52,15 +52,17 @@ struct VectorAllocator {
const std::size_t cap) noexcept {
// this totally idiotic redundant check (&& count <= Size) is required to address a bug in devkitARM,
// try removing it later
if (!std::is_constant_evaluated()) {
if (cap <= m_data.size() && count <= m_data.size()) {
for (auto i = 0u; i < count; ++i) {
const auto dstItem = reinterpret_cast<T*>(&m_data[i]);
const auto srcItem = reinterpret_cast<T*>(&src->m_data[i]);
const auto dstItem = reinterpret_cast<T *>(&m_data[i]);
const auto srcItem = reinterpret_cast<T *>(&src->m_data[i]);
std::construct_at<T>(dstItem, std::move(*srcItem));
}
*items = reinterpret_cast<T*>(m_data.data());
}
}
}
constexpr void moveItemsFrom(
T **items,
@ -69,22 +71,26 @@ struct VectorAllocator {
const std::size_t cap) noexcept {
// this totally idiotic redundant check (&& count <= Size) is required to address a bug in devkitARM,
// try removing it later
if (!std::is_constant_evaluated()) {
if (cap <= m_data.size() && count <= m_data.size()) {
for (std::size_t i = 0; i < count; ++i) {
const auto dstItem = reinterpret_cast<T*>(&m_data[i]);
const auto srcItem = reinterpret_cast<T*>(&src->m_data[i]);
const auto dstItem = reinterpret_cast<T *>(&m_data[i]);
const auto srcItem = reinterpret_cast<T *>(&src->m_data[i]);
*dstItem = std::move(*srcItem);
}
*items = reinterpret_cast<T*>(m_data.data());
}
}
}
constexpr void deallocate(T *items, std::size_t cap) noexcept {
// small vector optimization cannot be done it constexpr, but it doesn't really matter in constexpr
if (std::is_constant_evaluated() || (items && static_cast<void*>(items) != static_cast<void*>(m_data.data()))) {
if (std::is_constant_evaluated()) {
if (items && static_cast<void*>(items) != static_cast<void*>(m_data.data())) {
m_allocator.deallocate(items, cap);
}
}
}
};