From 2aa7284fe9828372c9fe7ffa8c231e561c0bf0a4 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Wed, 30 Jul 2025 00:42:42 -0500 Subject: [PATCH] Merge commit '1bfb7f99c215e2c74556bd3281f44962b8faaa96' (synced from f7c3c02c4cbe676ea116ea53f1f31b27f668cd98) --- src/ox/std/ignore.hpp | 2 +- src/ox/std/span.hpp | 18 ++++++++++++++++++ src/ox/std/string.hpp | 18 +++++++++--------- src/ox/std/strops.hpp | 20 +++++++++++++++----- src/ox/std/vector.hpp | 4 +++- 5 files changed, 46 insertions(+), 16 deletions(-) diff --git a/src/ox/std/ignore.hpp b/src/ox/std/ignore.hpp index 5dcaa5c9d..52fc42541 100644 --- a/src/ox/std/ignore.hpp +++ b/src/ox/std/ignore.hpp @@ -16,7 +16,7 @@ namespace std { -inline constexpr struct { +inline constexpr struct ignore_t { constexpr void operator=(auto&&) const noexcept {} } ignore; diff --git a/src/ox/std/span.hpp b/src/ox/std/span.hpp index 871dd8829..381e83eb9 100644 --- a/src/ox/std/span.hpp +++ b/src/ox/std/span.hpp @@ -163,6 +163,24 @@ class Span { return *this; } + constexpr Span operator++(int) noexcept { + ++m_items; + --m_size; + if (!m_size) [[unlikely]] { + m_items = nullptr; + } + return *this; + } + + constexpr Span operator++() noexcept { + ++m_items; + --m_size; + if (!m_size) [[unlikely]] { + m_items = nullptr; + } + return *this; + } + [[nodiscard]] constexpr auto data() const noexcept { return m_items; diff --git a/src/ox/std/string.hpp b/src/ox/std/string.hpp index 8a1cb7d00..d31f58be3 100644 --- a/src/ox/std/string.hpp +++ b/src/ox/std/string.hpp @@ -139,7 +139,7 @@ class BasicString { constexpr BasicString &operator+=(Integer_c auto i) noexcept; - constexpr BasicString &operator+=(StringView src) noexcept; + constexpr BasicString &operator+=(StringViewCR src) noexcept; constexpr BasicString &operator+=(BasicString const&src) noexcept; @@ -185,7 +185,7 @@ class BasicString { return {}; } - constexpr Error append(ox::StringView sv) noexcept { + constexpr Error append(StringViewCR sv) noexcept { return append(sv.data(), sv.size()); } @@ -376,7 +376,7 @@ constexpr BasicString &BasicString::operat } template -constexpr BasicString &BasicString::operator+=(StringView s) noexcept { +constexpr BasicString &BasicString::operator+=(StringViewCR s) noexcept { std::size_t strLen = s.bytes(); std::ignore = append(s.data(), strLen); return *this; @@ -456,7 +456,7 @@ constexpr bool BasicString::operator==(const char *other) con template constexpr bool BasicString::operator==(OxString_c auto const&other) const noexcept { - return ox::StringView(*this) == ox::StringView(other); + return StringView(*this) == StringView(other); } template @@ -548,28 +548,28 @@ using StringCR = String const&; [[nodiscard]] -constexpr ox::String toString(ox::StringViewCR sv) noexcept { +constexpr String toString(StringViewCR sv) noexcept { return ox::String(sv); } template [[nodiscard]] -constexpr auto sizeOf(const ox::BasicString*) noexcept { +constexpr auto sizeOf(BasicString const*) noexcept { VectorMemMap v{.smallVecSize = SmallStringSize_v}; return sizeOf(&v); } template [[nodiscard]] -constexpr auto alignOf(const ox::BasicString&) noexcept { +constexpr auto alignOf(BasicString const&) noexcept { VectorMemMap v{.smallVecSize = SmallStringSize_v}; return alignOf(&v); } template -struct MaybeView> { - using type = ox::StringView; +struct MaybeView> { + using type = StringView; }; } diff --git a/src/ox/std/strops.hpp b/src/ox/std/strops.hpp index b2f3ec99f..86251f447 100644 --- a/src/ox/std/strops.hpp +++ b/src/ox/std/strops.hpp @@ -21,7 +21,7 @@ OX_CLANG_NOWARN_BEGIN(-Wunsafe-buffer-usage) namespace ox { [[nodiscard]] -constexpr ox::StringView substr(ox::StringView const&str, std::size_t pos) noexcept { +constexpr StringView substr(StringViewCR str, std::size_t const pos) noexcept { if (str.size() >= pos) { return {&str[pos], str.size() - pos}; } @@ -29,13 +29,23 @@ constexpr ox::StringView substr(ox::StringView const&str, std::size_t pos) noexc } [[nodiscard]] -constexpr ox::StringView substr(ox::StringView const&str, std::size_t start, std::size_t end) noexcept { +constexpr StringView substr(StringViewCR str, std::size_t const start, std::size_t const end) noexcept { if (str.size() >= start && end >= start) { return {&str[start], end - start}; } return {}; } +[[nodiscard]] +constexpr bool beginsWith(StringViewCR base, char const beginning) noexcept { + return base.size() && base[0] == beginning; +} + +[[nodiscard]] +constexpr bool endsWith(StringViewCR base, char const ending) noexcept { + return base.size() && base[base.size() - 1] == ending; +} + [[nodiscard]] constexpr bool beginsWith(StringViewCR base, StringViewCR beginning) noexcept { const auto beginningLen = ox::min(beginning.size(), base.size()); @@ -49,7 +59,7 @@ constexpr bool endsWith(StringViewCR base, StringViewCR ending) noexcept { } [[nodiscard]] -constexpr std::size_t find(StringViewCR str, char search) noexcept { +constexpr std::size_t find(StringViewCR str, char const search) noexcept { std::size_t i = 0; for (; i < str.size(); ++i) { if (str[i] == search) { @@ -72,7 +82,7 @@ constexpr std::size_t find(StringViewCR str, StringViewCR search) noexcept { template [[nodiscard]] -constexpr ox::Vector split(StringViewCR str, char del) noexcept { +constexpr ox::Vector split(StringViewCR str, char const del) noexcept { ox::Vector out; constexpr auto nextSeg = [](StringViewCR current, char del) { return substr(current, find(current, del) + 1); @@ -105,7 +115,7 @@ constexpr ox::Vector split(StringViewCR str, StringView } [[nodiscard]] -constexpr ox::Result lastIndexOf(ox::StringViewCR str, int character) noexcept { +constexpr ox::Result lastIndexOf(ox::StringViewCR str, int const character) noexcept { ox::Result retval = ox::Error(1, "Character not found"); for (auto i = static_cast(str.bytes() - 1); i >= 0; --i) { if (str[static_cast(i)] == character) { diff --git a/src/ox/std/vector.hpp b/src/ox/std/vector.hpp index faab0650f..aa5706215 100644 --- a/src/ox/std/vector.hpp +++ b/src/ox/std/vector.hpp @@ -87,7 +87,9 @@ struct VectorAllocator { 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()) { - Allocator{}.deallocate(items, cap); + if (items) { + Allocator{}.deallocate(items, cap); + } } else { if (items && static_cast(items) != static_cast(m_data.data())) { Allocator{}.deallocate(items, cap);