[ox/std] Fix UPtr::reset to conform to unique_ptr::reset
(synced from aacff3daf9)
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
|
|
||||||
inline constexpr struct ignore_t {
|
inline constexpr struct {
|
||||||
constexpr void operator=(auto&&) const noexcept {}
|
constexpr void operator=(auto&&) const noexcept {}
|
||||||
} ignore;
|
} ignore;
|
||||||
|
|
||||||
|
|||||||
@@ -213,8 +213,7 @@ class UniquePtr {
|
|||||||
return m_t;
|
return m_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename UDeleter>
|
constexpr void reset(UniquePtr &&other = UniquePtr()) {
|
||||||
constexpr void reset(UniquePtr<U, UDeleter> &&other = UniquePtr()) {
|
|
||||||
auto t = m_t;
|
auto t = m_t;
|
||||||
m_t = other.release();
|
m_t = other.release();
|
||||||
Deleter()(t);
|
Deleter()(t);
|
||||||
|
|||||||
@@ -163,24 +163,6 @@ class Span {
|
|||||||
return *this;
|
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]]
|
[[nodiscard]]
|
||||||
constexpr auto data() const noexcept {
|
constexpr auto data() const noexcept {
|
||||||
return m_items;
|
return m_items;
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ class BasicString {
|
|||||||
|
|
||||||
constexpr BasicString &operator+=(Integer_c auto i) noexcept;
|
constexpr BasicString &operator+=(Integer_c auto i) noexcept;
|
||||||
|
|
||||||
constexpr BasicString &operator+=(StringViewCR src) noexcept;
|
constexpr BasicString &operator+=(StringView src) noexcept;
|
||||||
|
|
||||||
constexpr BasicString &operator+=(BasicString const&src) noexcept;
|
constexpr BasicString &operator+=(BasicString const&src) noexcept;
|
||||||
|
|
||||||
@@ -185,7 +185,7 @@ class BasicString {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Error append(StringViewCR sv) noexcept {
|
constexpr Error append(ox::StringView sv) noexcept {
|
||||||
return append(sv.data(), sv.size());
|
return append(sv.data(), sv.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,7 +376,7 @@ constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operat
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t SmallStringSize_v>
|
template<std::size_t SmallStringSize_v>
|
||||||
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator+=(StringViewCR s) noexcept {
|
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator+=(StringView s) noexcept {
|
||||||
std::size_t strLen = s.bytes();
|
std::size_t strLen = s.bytes();
|
||||||
std::ignore = append(s.data(), strLen);
|
std::ignore = append(s.data(), strLen);
|
||||||
return *this;
|
return *this;
|
||||||
@@ -456,7 +456,7 @@ constexpr bool BasicString<SmallStringSize_v>::operator==(const char *other) con
|
|||||||
|
|
||||||
template<std::size_t SmallStringSize_v>
|
template<std::size_t SmallStringSize_v>
|
||||||
constexpr bool BasicString<SmallStringSize_v>::operator==(OxString_c auto const&other) const noexcept {
|
constexpr bool BasicString<SmallStringSize_v>::operator==(OxString_c auto const&other) const noexcept {
|
||||||
return StringView(*this) == StringView(other);
|
return ox::StringView(*this) == ox::StringView(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t SmallStringSize_v>
|
template<std::size_t SmallStringSize_v>
|
||||||
@@ -548,28 +548,28 @@ using StringCR = String const&;
|
|||||||
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr String toString(StringViewCR sv) noexcept {
|
constexpr ox::String toString(ox::StringViewCR sv) noexcept {
|
||||||
return ox::String(sv);
|
return ox::String(sv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename PlatSpec, std::size_t SmallStringSize_v>
|
template<typename PlatSpec, std::size_t SmallStringSize_v>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr auto sizeOf(BasicString<SmallStringSize_v> const*) noexcept {
|
constexpr auto sizeOf(const ox::BasicString<SmallStringSize_v>*) noexcept {
|
||||||
VectorMemMap<PlatSpec> v{.smallVecSize = SmallStringSize_v};
|
VectorMemMap<PlatSpec> v{.smallVecSize = SmallStringSize_v};
|
||||||
return sizeOf<PlatSpec>(&v);
|
return sizeOf<PlatSpec>(&v);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename PlatSpec, std::size_t SmallStringSize_v>
|
template<typename PlatSpec, std::size_t SmallStringSize_v>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr auto alignOf(BasicString<SmallStringSize_v> const&) noexcept {
|
constexpr auto alignOf(const ox::BasicString<SmallStringSize_v>&) noexcept {
|
||||||
VectorMemMap<PlatSpec> v{.smallVecSize = SmallStringSize_v};
|
VectorMemMap<PlatSpec> v{.smallVecSize = SmallStringSize_v};
|
||||||
return alignOf<PlatSpec>(&v);
|
return alignOf<PlatSpec>(&v);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<size_t sz>
|
template<size_t sz>
|
||||||
struct MaybeView<BasicString<sz>> {
|
struct MaybeView<ox::BasicString<sz>> {
|
||||||
using type = StringView;
|
using type = ox::StringView;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-15
@@ -21,7 +21,7 @@ OX_CLANG_NOWARN_BEGIN(-Wunsafe-buffer-usage)
|
|||||||
namespace ox {
|
namespace ox {
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr StringView substr(StringViewCR str, std::size_t const pos) noexcept {
|
constexpr ox::StringView substr(ox::StringView const&str, std::size_t pos) noexcept {
|
||||||
if (str.size() >= pos) {
|
if (str.size() >= pos) {
|
||||||
return {&str[pos], str.size() - pos};
|
return {&str[pos], str.size() - pos};
|
||||||
}
|
}
|
||||||
@@ -29,23 +29,13 @@ constexpr StringView substr(StringViewCR str, std::size_t const pos) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr StringView substr(StringViewCR str, std::size_t const start, std::size_t const end) noexcept {
|
constexpr ox::StringView substr(ox::StringView const&str, std::size_t start, std::size_t end) noexcept {
|
||||||
if (str.size() >= start && end >= start) {
|
if (str.size() >= start && end >= start) {
|
||||||
return {&str[start], end - start};
|
return {&str[start], end - start};
|
||||||
}
|
}
|
||||||
return {};
|
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]]
|
[[nodiscard]]
|
||||||
constexpr bool beginsWith(StringViewCR base, StringViewCR beginning) noexcept {
|
constexpr bool beginsWith(StringViewCR base, StringViewCR beginning) noexcept {
|
||||||
const auto beginningLen = ox::min(beginning.size(), base.size());
|
const auto beginningLen = ox::min(beginning.size(), base.size());
|
||||||
@@ -59,7 +49,7 @@ constexpr bool endsWith(StringViewCR base, StringViewCR ending) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr std::size_t find(StringViewCR str, char const search) noexcept {
|
constexpr std::size_t find(StringViewCR str, char search) noexcept {
|
||||||
std::size_t i = 0;
|
std::size_t i = 0;
|
||||||
for (; i < str.size(); ++i) {
|
for (; i < str.size(); ++i) {
|
||||||
if (str[i] == search) {
|
if (str[i] == search) {
|
||||||
@@ -82,7 +72,7 @@ constexpr std::size_t find(StringViewCR str, StringViewCR search) noexcept {
|
|||||||
|
|
||||||
template<std::size_t smallSz = 0>
|
template<std::size_t smallSz = 0>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr ox::Vector<ox::StringView, smallSz> split(StringViewCR str, char const del) noexcept {
|
constexpr ox::Vector<ox::StringView, smallSz> split(StringViewCR str, char del) noexcept {
|
||||||
ox::Vector<ox::StringView, smallSz> out;
|
ox::Vector<ox::StringView, smallSz> out;
|
||||||
constexpr auto nextSeg = [](StringViewCR current, char del) {
|
constexpr auto nextSeg = [](StringViewCR current, char del) {
|
||||||
return substr(current, find(current, del) + 1);
|
return substr(current, find(current, del) + 1);
|
||||||
@@ -115,7 +105,7 @@ constexpr ox::Vector<ox::StringView, smallSz> split(StringViewCR str, StringView
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr ox::Result<std::size_t> lastIndexOf(ox::StringViewCR str, int const character) noexcept {
|
constexpr ox::Result<std::size_t> lastIndexOf(ox::StringViewCR str, int character) noexcept {
|
||||||
ox::Result<std::size_t> retval = ox::Error(1, "Character not found");
|
ox::Result<std::size_t> retval = ox::Error(1, "Character not found");
|
||||||
for (auto i = static_cast<int>(str.bytes() - 1); i >= 0; --i) {
|
for (auto i = static_cast<int>(str.bytes() - 1); i >= 0; --i) {
|
||||||
if (str[static_cast<std::size_t>(i)] == character) {
|
if (str[static_cast<std::size_t>(i)] == character) {
|
||||||
|
|||||||
@@ -87,9 +87,7 @@ struct VectorAllocator {
|
|||||||
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()) {
|
if (std::is_constant_evaluated()) {
|
||||||
if (items) {
|
Allocator{}.deallocate(items, cap);
|
||||||
Allocator{}.deallocate(items, cap);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (items && static_cast<void*>(items) != static_cast<void*>(m_data.data())) {
|
if (items && static_cast<void*>(items) != static_cast<void*>(m_data.data())) {
|
||||||
Allocator{}.deallocate(items, cap);
|
Allocator{}.deallocate(items, cap);
|
||||||
|
|||||||
Reference in New Issue
Block a user