[ox/std] Silently suppress small Vector in constexpr
This commit is contained in:
parent
60b97094b0
commit
50eb01115d
37
deps/ox/src/ox/std/vector.hpp
vendored
37
deps/ox/src/ox/std/vector.hpp
vendored
@ -22,25 +22,25 @@ namespace ox {
|
|||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
template<typename T, std::size_t Size>
|
template<typename T, std::size_t Size>
|
||||||
struct SmallVector {
|
struct VectorAllocator {
|
||||||
private:
|
private:
|
||||||
std::allocator<T> m_allocator;
|
std::allocator<T> m_allocator;
|
||||||
AllocAlias<T> m_data[Size] = {};
|
AllocAlias<T> m_data[Size] = {};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SmallVector() noexcept = default;
|
constexpr VectorAllocator() noexcept = default;
|
||||||
SmallVector(SmallVector&) noexcept = default;
|
constexpr VectorAllocator(VectorAllocator&) noexcept = default;
|
||||||
SmallVector(SmallVector&&) noexcept = default;
|
constexpr VectorAllocator(VectorAllocator&&) noexcept = default;
|
||||||
protected:
|
protected:
|
||||||
constexpr void allocate(T **items, std::size_t cap) noexcept {
|
constexpr void allocate(T **items, std::size_t cap) noexcept {
|
||||||
if (cap <= Size) {
|
// small vector optimization cannot be done it constexpr, but it doesn't really matter in constexpr
|
||||||
*items = reinterpret_cast<T*>(m_data);
|
if (std::is_constant_evaluated() || cap > Size) {
|
||||||
} else {
|
|
||||||
*items = m_allocator.allocate(cap);
|
*items = m_allocator.allocate(cap);
|
||||||
|
} else {
|
||||||
|
*items = reinterpret_cast<T*>(m_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr void moveConstructItemsFrom(T **items, SmallVector &src, const std::size_t count, const std::size_t cap) noexcept {
|
constexpr void moveConstructItemsFrom(T **items, VectorAllocator &src, const std::size_t count, const std::size_t cap) noexcept {
|
||||||
if (cap <= Size) {
|
if (cap <= Size) {
|
||||||
const auto dstItems = reinterpret_cast<T*>(m_data);
|
const auto dstItems = reinterpret_cast<T*>(m_data);
|
||||||
const auto srcItems = reinterpret_cast<T*>(src.m_data);
|
const auto srcItems = reinterpret_cast<T*>(src.m_data);
|
||||||
@ -51,7 +51,7 @@ struct SmallVector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr void moveItemsFrom(T **items, SmallVector &src, const std::size_t count, const std::size_t cap) noexcept {
|
constexpr void moveItemsFrom(T **items, VectorAllocator &src, const std::size_t count, 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 (cap <= Size && count <= Size) {
|
if (cap <= Size && count <= Size) {
|
||||||
@ -65,7 +65,8 @@ struct SmallVector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constexpr void deallocate(T *items, std::size_t cap) noexcept {
|
constexpr void deallocate(T *items, std::size_t cap) noexcept {
|
||||||
if (items && static_cast<void*>(items) != static_cast<void*>(m_data)) {
|
// 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))) {
|
||||||
m_allocator.deallocate(items, cap);
|
m_allocator.deallocate(items, cap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,24 +74,24 @@ struct SmallVector {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct SmallVector<T, 0> {
|
struct VectorAllocator<T, 0> {
|
||||||
private:
|
private:
|
||||||
std::allocator<T> m_allocator;
|
std::allocator<T> m_allocator;
|
||||||
public:
|
public:
|
||||||
SmallVector() noexcept = default;
|
constexpr VectorAllocator() noexcept = default;
|
||||||
SmallVector(SmallVector&) noexcept = default;
|
constexpr VectorAllocator(VectorAllocator&) noexcept = default;
|
||||||
SmallVector(SmallVector&&) noexcept = default;
|
constexpr VectorAllocator(VectorAllocator&&) noexcept = default;
|
||||||
protected:
|
protected:
|
||||||
constexpr void allocate(T **items, std::size_t cap) noexcept {
|
constexpr void allocate(T **items, std::size_t cap) noexcept {
|
||||||
*items = m_allocator.allocate(cap);
|
*items = m_allocator.allocate(cap);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[maybe_unused]]
|
[[maybe_unused]]
|
||||||
constexpr void moveConstructItemsFrom(T**, SmallVector&, const std::size_t, const std::size_t) noexcept {
|
constexpr void moveConstructItemsFrom(T**, VectorAllocator&, const std::size_t, const std::size_t) noexcept {
|
||||||
}
|
}
|
||||||
|
|
||||||
[[maybe_unused]]
|
[[maybe_unused]]
|
||||||
constexpr void moveItemsFrom(T**, SmallVector&, const std::size_t, const std::size_t) noexcept {
|
constexpr void moveItemsFrom(T**, VectorAllocator&, const std::size_t, const std::size_t) noexcept {
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr void deallocate(T *items, std::size_t cap) noexcept {
|
constexpr void deallocate(T *items, std::size_t cap) noexcept {
|
||||||
@ -104,7 +105,7 @@ struct SmallVector<T, 0> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, std::size_t SmallVectorSize = 0>
|
template<typename T, std::size_t SmallVectorSize = 0>
|
||||||
class Vector: detail::SmallVector<T, SmallVectorSize> {
|
class Vector: detail::VectorAllocator<T, SmallVectorSize> {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using value_type = T;
|
using value_type = T;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user