[ox] Fix for C++20
This commit is contained in:
parent
e91d2653a3
commit
f61efbafaf
9
deps/ox/src/ox/model/fieldcounter.hpp
vendored
9
deps/ox/src/ox/model/fieldcounter.hpp
vendored
@ -48,13 +48,10 @@ class FieldCounter {
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
#if __cplusplus >= 202002L
|
||||
consteval
|
||||
#endif
|
||||
int countFields() noexcept {
|
||||
AllocAlias<T> a = {};
|
||||
constexpr int countFields() noexcept {
|
||||
T t;
|
||||
FieldCounter<T> c;
|
||||
oxIgnoreError(model(&c, std::bit_cast<T*>(&a)));
|
||||
oxIgnoreError(model(&c, &t));
|
||||
return c.fields;
|
||||
}
|
||||
|
||||
|
13
deps/ox/src/ox/model/typenamecatcher.hpp
vendored
13
deps/ox/src/ox/model/typenamecatcher.hpp
vendored
@ -44,21 +44,18 @@ struct TypeNameCatcher {
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
#if __cplusplus >= 202002L
|
||||
consteval
|
||||
#endif
|
||||
const char *getModelTypeName() noexcept {
|
||||
AllocAlias<T> a = {};
|
||||
constexpr const char *getModelTypeName() noexcept {
|
||||
T t;
|
||||
TypeNameCatcher nc;
|
||||
oxIgnoreError(model(&nc, std::bit_cast<T*>(&a)));
|
||||
oxIgnoreError(model(&nc, &t));
|
||||
return nc.name;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr const char *getModelTypeName(T *val) noexcept {
|
||||
TypeNameCatcher nc;
|
||||
oxIgnoreError(model(&nc, std::bit_cast<T*>(&val)));
|
||||
oxIgnoreError(model(&nc, val));
|
||||
return nc.name;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
4
deps/ox/src/ox/std/bit.hpp
vendored
4
deps/ox/src/ox/std/bit.hpp
vendored
@ -61,8 +61,8 @@ namespace std {
|
||||
#if __cplusplus >= 202002L && !defined(OX_USE_STDLIB)
|
||||
|
||||
template<typename To, typename From>
|
||||
constexpr typename ox::enable_if<sizeof(To) == sizeof(From), To>::type bit_cast(From src) noexcept {
|
||||
return __builtin_bitcast(src);
|
||||
constexpr typename ox::enable_if<sizeof(To) == sizeof(From), To>::type bit_cast(const From &src) noexcept {
|
||||
return __builtin_bit_cast(To, src);
|
||||
}
|
||||
|
||||
#elif __cplusplus < 202002L
|
||||
|
2
deps/ox/src/ox/std/error.hpp
vendored
2
deps/ox/src/ox/std/error.hpp
vendored
@ -172,7 +172,7 @@ constexpr Error toError(const Result<T> &ve) noexcept {
|
||||
constexpr void oxIgnoreError(const ox::Error&) noexcept {}
|
||||
#if __cplusplus >= 202002L
|
||||
#define oxReturnError(x) if (const auto _ox_error = ox::detail::toError(x)) [[unlikely]] return _ox_error
|
||||
#define oxThrowError(x) if (const auto _ox_error = ox::detail::toError(x)) [[unlikely]] ox::Exception(_ox_error)
|
||||
#define oxThrowError(x) if (const auto _ox_error = ox::detail::toError(x)) [[unlikely]] throw ox::Exception(_ox_error)
|
||||
#else
|
||||
#define oxReturnError(err) if (const auto _ox_error = ox::detail::toError(err)) return _ox_error
|
||||
#define oxThrowError(err) if (const auto _ox_error = ox::detail::toError(err)) throw ox::Exception(_ox_error)
|
||||
|
4
deps/ox/src/ox/std/fmt.hpp
vendored
4
deps/ox/src/ox/std/fmt.hpp
vendored
@ -42,11 +42,7 @@ constexpr const char *toCString(const BasicString<size> &s) noexcept {
|
||||
}
|
||||
|
||||
#if __has_include(<string>)
|
||||
#if __cplusplus >= 202002L
|
||||
constexpr
|
||||
#else
|
||||
inline
|
||||
#endif
|
||||
const char *toCString(const std::string &s) noexcept {
|
||||
return s.c_str();
|
||||
}
|
||||
|
34
deps/ox/src/ox/std/vector.hpp
vendored
34
deps/ox/src/ox/std/vector.hpp
vendored
@ -32,31 +32,31 @@ struct SmallVector {
|
||||
protected:
|
||||
constexpr void initItems(T **items, std::size_t cap) noexcept {
|
||||
if (cap <= Size) {
|
||||
*items = std::bit_cast<T*>(m_data);
|
||||
*items = reinterpret_cast<T*>(m_data);
|
||||
} else {
|
||||
*items = std::bit_cast<T*>(new AllocAlias<T>[cap]);
|
||||
*items = reinterpret_cast<T*>(new AllocAlias<T>[cap]);
|
||||
}
|
||||
}
|
||||
|
||||
constexpr void moveConstructItemsFrom(T **items, SmallVector &src, const std::size_t count, const std::size_t cap) noexcept {
|
||||
if (cap <= Size) {
|
||||
const auto dstItems = bit_cast<T*>(m_data);
|
||||
const auto srcItems = bit_cast<T*>(src.m_data);
|
||||
const auto dstItems = reinterpret_cast<T*>(m_data);
|
||||
const auto srcItems = reinterpret_cast<T*>(src.m_data);
|
||||
for (auto i = 0u; i < count; ++i) {
|
||||
new (&dstItems[i]) T(move(srcItems[i]));
|
||||
}
|
||||
*items = bit_cast<T*>(m_data);
|
||||
*items = reinterpret_cast<T*>(m_data);
|
||||
}
|
||||
}
|
||||
|
||||
constexpr void moveItemsFrom(T **items, SmallVector &src, const std::size_t count, const std::size_t cap) noexcept {
|
||||
if (cap <= Size) {
|
||||
const auto dstItems = std::bit_cast<T*>(m_data);
|
||||
const auto srcItems = std::bit_cast<T*>(src.m_data);
|
||||
const auto dstItems = reinterpret_cast<T*>(m_data);
|
||||
const auto srcItems = reinterpret_cast<T*>(src.m_data);
|
||||
for (auto i = 0u; i < count; ++i) {
|
||||
dstItems[i] = move(srcItems[i]);
|
||||
}
|
||||
*items = std::bit_cast<T*>(m_data);
|
||||
*items = reinterpret_cast<T*>(m_data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ struct SmallVector<T, 0> {
|
||||
SmallVector(SmallVector&&) noexcept = default;
|
||||
protected:
|
||||
constexpr void initItems(T **items, std::size_t cap) noexcept {
|
||||
*items = std::bit_cast<T*>(new AllocAlias<T>[cap]);
|
||||
*items = reinterpret_cast<T*>(new AllocAlias<T>[cap]);
|
||||
}
|
||||
|
||||
[[maybe_unused]]
|
||||
@ -382,7 +382,7 @@ Vector<T, SmallVectorSize>::Vector(Vector &&other) noexcept {
|
||||
template<typename T, std::size_t SmallVectorSize>
|
||||
Vector<T, SmallVectorSize>::~Vector() {
|
||||
clear();
|
||||
this->clearItems(std::bit_cast<AllocAlias<T>*>(m_items));
|
||||
this->clearItems(reinterpret_cast<AllocAlias<T>*>(m_items));
|
||||
m_items = nullptr;
|
||||
}
|
||||
|
||||
@ -403,7 +403,7 @@ template<typename T, std::size_t SmallVectorSize>
|
||||
constexpr Vector<T, SmallVectorSize> &Vector<T, SmallVectorSize>::operator=(const Vector &other) {
|
||||
if (this != &other) {
|
||||
clear();
|
||||
this->clearItems(std::bit_cast<AllocAlias<T>*>(m_items));
|
||||
this->clearItems(reinterpret_cast<AllocAlias<T>*>(m_items));
|
||||
m_items = nullptr;
|
||||
m_size = other.m_size;
|
||||
m_cap = other.m_cap;
|
||||
@ -419,7 +419,7 @@ template<typename T, std::size_t SmallVectorSize>
|
||||
constexpr Vector<T, SmallVectorSize> &Vector<T, SmallVectorSize>::operator=(Vector &&other) noexcept {
|
||||
if (this != &other) {
|
||||
clear();
|
||||
this->clearItems(std::bit_cast<AllocAlias<T>*>(m_items));
|
||||
this->clearItems(reinterpret_cast<AllocAlias<T>*>(m_items));
|
||||
m_size = other.m_size;
|
||||
m_cap = other.m_cap;
|
||||
m_items = other.m_items;
|
||||
@ -445,7 +445,7 @@ template<typename T, std::size_t SmallVectorSize>
|
||||
Result<T&> Vector<T, SmallVectorSize>::front() noexcept {
|
||||
if (!m_size) {
|
||||
AllocAlias<T> v;
|
||||
return {*std::bit_cast<T*>(&v), OxError(1)};
|
||||
return {*reinterpret_cast<T*>(&v), OxError(1)};
|
||||
}
|
||||
return m_items[0];
|
||||
}
|
||||
@ -454,7 +454,7 @@ template<typename T, std::size_t SmallVectorSize>
|
||||
Result<const T&> Vector<T, SmallVectorSize>::front() const noexcept {
|
||||
if (!m_size) {
|
||||
AllocAlias<T> v;
|
||||
return {*std::bit_cast<T*>(&v), OxError(1)};
|
||||
return {*reinterpret_cast<T*>(&v), OxError(1)};
|
||||
}
|
||||
return m_items[0];
|
||||
}
|
||||
@ -463,7 +463,7 @@ template<typename T, std::size_t SmallVectorSize>
|
||||
Result<T&> Vector<T, SmallVectorSize>::back() noexcept {
|
||||
if (!m_size) {
|
||||
AllocAlias<T> v;
|
||||
return {*std::bit_cast<T*>(&v), OxError(1)};
|
||||
return {*reinterpret_cast<T*>(&v), OxError(1)};
|
||||
}
|
||||
return m_items[m_size - 1];
|
||||
}
|
||||
@ -472,7 +472,7 @@ template<typename T, std::size_t SmallVectorSize>
|
||||
Result<const T&> Vector<T, SmallVectorSize>::back() const noexcept {
|
||||
if (!m_size) {
|
||||
AllocAlias<T> v;
|
||||
return {*std::bit_cast<T*>(&v), OxError(1)};
|
||||
return {*reinterpret_cast<T*>(&v), OxError(1)};
|
||||
}
|
||||
return m_items[m_size - 1];
|
||||
}
|
||||
@ -604,7 +604,7 @@ void Vector<T, SmallVectorSize>::expandCap(std::size_t cap) {
|
||||
for (std::size_t i = itRange; i < m_cap; i++) {
|
||||
new (&m_items[i]) T;
|
||||
}
|
||||
this->clearItems(std::bit_cast<AllocAlias<T>*>(oldItems));
|
||||
this->clearItems(reinterpret_cast<AllocAlias<T>*>(oldItems));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user