From f572b1357dd2e8c567811431d87478a1d5eb33b7 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 21 Apr 2024 13:13:26 -0500 Subject: [PATCH] Merge commit 'c0baf7efca0e4c3a86a018ad2564d9df7b07c133' (synced from d7f309750e988e189e9c22b49f3cf56b4d958a5b) --- src/ox/model/typenamecatcher.hpp | 15 ++++++++++++++ src/ox/std/CMakeLists.txt | 1 + src/ox/std/fmt.hpp | 2 +- src/ox/std/ignore.hpp | 20 +++++++++++++++++++ src/ox/std/realstd.hpp | 2 +- src/ox/std/std.hpp | 1 + src/ox/std/strops.hpp | 4 ++++ src/ox/std/typetraits.hpp | 10 +++++----- src/ox/std/vector.hpp | 34 +++++++++++++++++++------------- 9 files changed, 68 insertions(+), 21 deletions(-) create mode 100644 src/ox/std/ignore.hpp diff --git a/src/ox/model/typenamecatcher.hpp b/src/ox/model/typenamecatcher.hpp index d2b555d4e..c83fca2fc 100644 --- a/src/ox/model/typenamecatcher.hpp +++ b/src/ox/model/typenamecatcher.hpp @@ -147,4 +147,19 @@ constexpr auto ModelTypeName_v = getModelTypeName(); template constexpr auto ModelTypeVersion_v = requireModelTypeVersion(); +template +constexpr auto ModelTypeVersionStr_v = [] { + constexpr auto version = ModelTypeVersion_v; + constexpr auto versionStr = ox::sfmt("{}", version); + return ox::BString{versionStr}; +}; + +template +constexpr auto ModelTypeId_v = [] { + constexpr auto name = ModelTypeName_v; + constexpr auto version = ModelTypeVersion_v; + constexpr auto versionStr = ox::sfmt>("{}", version); + return ox::sfmt>("{};{}", name, versionStr); +}(); + } diff --git a/src/ox/std/CMakeLists.txt b/src/ox/std/CMakeLists.txt index 73c005783..fbf8adb9d 100644 --- a/src/ox/std/CMakeLists.txt +++ b/src/ox/std/CMakeLists.txt @@ -103,6 +103,7 @@ install( hardware.hpp hashmap.hpp heapmgr.hpp + ignore.hpp iterator.hpp math.hpp maybeview.hpp diff --git a/src/ox/std/fmt.hpp b/src/ox/std/fmt.hpp index b650bbefe..aa13b0b41 100644 --- a/src/ox/std/fmt.hpp +++ b/src/ox/std/fmt.hpp @@ -77,7 +77,7 @@ class FmtArg { char dataStr[10] = {}; template - static StringView sv(const T &v, char *dataStr) noexcept { + constexpr StringView sv(const T &v, char *dataStr) noexcept { if constexpr(is_bool_v) { return v ? "true" : "false"; } else if constexpr(is_integer_v) { diff --git a/src/ox/std/ignore.hpp b/src/ox/std/ignore.hpp new file mode 100644 index 000000000..5ce40f0c2 --- /dev/null +++ b/src/ox/std/ignore.hpp @@ -0,0 +1,20 @@ +/* + * Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved. + */ + +#pragma once + +#if __has_include() + +#include + +#else + +namespace std { + +inline constexpr struct { + constexpr void operator=(auto&&) const noexcept {} +} ignore; + +} +#endif diff --git a/src/ox/std/realstd.hpp b/src/ox/std/realstd.hpp index d4441a541..73b7ae31b 100644 --- a/src/ox/std/realstd.hpp +++ b/src/ox/std/realstd.hpp @@ -11,5 +11,5 @@ #if __has_include() #include #else -#define assert(e) while (1); +#define assert(e) while (!(e)); #endif \ No newline at end of file diff --git a/src/ox/std/std.hpp b/src/ox/std/std.hpp index 9f55f5016..d2baca986 100644 --- a/src/ox/std/std.hpp +++ b/src/ox/std/std.hpp @@ -26,6 +26,7 @@ #include "hardware.hpp" #include "hashmap.hpp" #include "heapmgr.hpp" +#include "ignore.hpp" #include "iterator.hpp" #include "math.hpp" #include "maybeview.hpp" diff --git a/src/ox/std/strops.hpp b/src/ox/std/strops.hpp index 84be901fc..e3f63f646 100644 --- a/src/ox/std/strops.hpp +++ b/src/ox/std/strops.hpp @@ -80,6 +80,7 @@ constexpr bool endsWith(CRStringView base, CRStringView ending) noexcept { return base.len() >= endingLen && ox::strcmp(base.data() + (base.len() - endingLen), ending) == 0; } +[[nodiscard]] constexpr std::size_t find(CRStringView str, char search) noexcept { std::size_t i = 0; for (; i < str.len(); ++i) { @@ -90,6 +91,7 @@ constexpr std::size_t find(CRStringView str, char search) noexcept { return i; } +[[nodiscard]] constexpr std::size_t find(CRStringView str, CRStringView search) noexcept { std::size_t i = 0; for (; i < str.len(); ++i) { @@ -101,6 +103,7 @@ constexpr std::size_t find(CRStringView str, CRStringView search) noexcept { } template +[[nodiscard]] constexpr ox::Vector split(CRStringView str, char del) noexcept { ox::Vector out; constexpr auto nextSeg = [](CRStringView current, char del) { @@ -117,6 +120,7 @@ constexpr ox::Vector split(CRStringView str, char del) } template +[[nodiscard]] constexpr ox::Vector split(CRStringView str, CRStringView del) noexcept { ox::Vector out; constexpr auto nextSeg = [](CRStringView current, CRStringView del) { diff --git a/src/ox/std/typetraits.hpp b/src/ox/std/typetraits.hpp index fbc927091..4b480f474 100644 --- a/src/ox/std/typetraits.hpp +++ b/src/ox/std/typetraits.hpp @@ -143,7 +143,7 @@ template constexpr bool memberable(...) { return false; } template -struct is_class: integral_constant::value && memberable(0)> {}; +struct is_class: integral_constant && memberable(nullptr)> {}; namespace test { struct TestClass {int i;}; @@ -159,11 +159,11 @@ constexpr bool is_class_v = is_class(); template constexpr bool is_signed_v = integral_constant::value; -template -concept Signed_c = is_signed_v && sizeof(T) == 8 * bits; +template +concept Signed_c = is_signed_v && sizeof(T) == bits / 8; -template -concept Unsigned_c = !is_signed_v && sizeof(T) == 8 * bits; +template +concept Unsigned_c = !is_signed_v && sizeof(T) == bits / 8; template struct is_same: false_type {}; diff --git a/src/ox/std/vector.hpp b/src/ox/std/vector.hpp index 05f377aba..56be6e136 100644 --- a/src/ox/std/vector.hpp +++ b/src/ox/std/vector.hpp @@ -52,13 +52,15 @@ 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 (cap <= m_data.size() && count <= m_data.size()) { - for (auto i = 0u; i < count; ++i) { - const auto dstItem = reinterpret_cast(&m_data[i]); - const auto srcItem = reinterpret_cast(&src->m_data[i]); - std::construct_at(dstItem, std::move(*srcItem)); + 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(&m_data[i]); + const auto srcItem = reinterpret_cast(&src->m_data[i]); + std::construct_at(dstItem, std::move(*srcItem)); + } + *items = reinterpret_cast(m_data.data()); } - *items = reinterpret_cast(m_data.data()); } } @@ -69,20 +71,24 @@ 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 (cap <= m_data.size() && count <= m_data.size()) { - for (std::size_t i = 0; i < count; ++i) { - const auto dstItem = reinterpret_cast(&m_data[i]); - const auto srcItem = reinterpret_cast(&src->m_data[i]); - *dstItem = std::move(*srcItem); + 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(&m_data[i]); + const auto srcItem = reinterpret_cast(&src->m_data[i]); + *dstItem = std::move(*srcItem); + } + *items = reinterpret_cast(m_data.data()); } - *items = reinterpret_cast(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(items) != static_cast(m_data.data()))) { - m_allocator.deallocate(items, cap); + if (std::is_constant_evaluated()) { + if (items && static_cast(items) != static_cast(m_data.data())) { + m_allocator.deallocate(items, cap); + } } }