[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,6 +52,7 @@ struct VectorAllocator {
const std::size_t cap) noexcept { const std::size_t cap) noexcept {
// this totally idiotic redundant check (&& count <= Size) is required to address a bug in devkitARM, // this totally idiotic redundant check (&& count <= Size) is required to address a bug in devkitARM,
// try removing it later // try removing it later
if (!std::is_constant_evaluated()) {
if (cap <= m_data.size() && count <= m_data.size()) { if (cap <= m_data.size() && count <= m_data.size()) {
for (auto i = 0u; i < count; ++i) { for (auto i = 0u; i < count; ++i) {
const auto dstItem = reinterpret_cast<T *>(&m_data[i]); const auto dstItem = reinterpret_cast<T *>(&m_data[i]);
@ -61,6 +62,7 @@ struct VectorAllocator {
*items = reinterpret_cast<T*>(m_data.data()); *items = reinterpret_cast<T*>(m_data.data());
} }
} }
}
constexpr void moveItemsFrom( constexpr void moveItemsFrom(
T **items, T **items,
@ -69,6 +71,7 @@ struct VectorAllocator {
const std::size_t cap) noexcept { const std::size_t cap) noexcept {
// this totally idiotic redundant check (&& count <= Size) is required to address a bug in devkitARM, // this totally idiotic redundant check (&& count <= Size) is required to address a bug in devkitARM,
// try removing it later // try removing it later
if (!std::is_constant_evaluated()) {
if (cap <= m_data.size() && count <= m_data.size()) { if (cap <= m_data.size() && count <= m_data.size()) {
for (std::size_t i = 0; i < count; ++i) { for (std::size_t i = 0; i < count; ++i) {
const auto dstItem = reinterpret_cast<T *>(&m_data[i]); const auto dstItem = reinterpret_cast<T *>(&m_data[i]);
@ -78,13 +81,16 @@ struct VectorAllocator {
*items = reinterpret_cast<T*>(m_data.data()); *items = reinterpret_cast<T*>(m_data.data());
} }
} }
}
constexpr void deallocate(T *items, std::size_t cap) noexcept { 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 // 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); m_allocator.deallocate(items, cap);
} }
} }
}
}; };