From ed50041589974d31296cb30dc1897f7fba6336c2 Mon Sep 17 00:00:00 2001 From: B Stack Date: Wed, 20 Nov 2019 08:36:44 -0500 Subject: add upstream 10.18 --- zen/string_base.h | 52 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 8 deletions(-) (limited to 'zen/string_base.h') diff --git a/zen/string_base.h b/zen/string_base.h index a417b7f6..6c835c72 100644 --- a/zen/string_base.h +++ b/zen/string_base.h @@ -12,6 +12,9 @@ #include #include #include "string_tools.h" +#if __cpp_impl_three_way_comparison && __cpp_lib_three_way_comparison + #include +#endif //Zbase - a policy based string class optimizing performance and flexibility @@ -189,11 +192,10 @@ private: length (static_cast(len)), capacity(static_cast(cap)) { - //static_assert(ATOMIC_INT_LOCK_FREE == 2); //2: "The atomic type is always lock-free" - static_assert(decltype(refCount)::is_always_lock_free); //C++17 variant (not yet supported on GCC 6.3) + static_assert(decltype(refCount)::is_always_lock_free); } - std::atomic refCount { 1 }; //std:atomic is uninitialized by default! + std::atomic refCount { 1 }; //std:atomic is uninitialized by default! uint32_t length; const uint32_t capacity; //allocated size without null-termination }; @@ -289,10 +291,22 @@ private: Char* rawStr_; }; + +#if __cpp_impl_three_way_comparison && __cpp_lib_three_way_comparison + #error implement! +#endif + + template class SP> bool operator==(const Zbase& lhs, const Zbase& rhs); template class SP> bool operator==(const Zbase& lhs, const Char* rhs); template class SP> inline bool operator==(const Char* lhs, const Zbase& rhs) { return operator==(rhs, lhs); } +#if __cpp_impl_three_way_comparison && __cpp_lib_three_way_comparison +template class SP> std::strong_ordering operator<=>(const Zbase& lhs, const Zbase& rhs); +template class SP> std::strong_ordering operator<=>(const Zbase& lhs, const Char* rhs); +template class SP> std::strong_ordering operator<=>(const Char* lhs, const Zbase& rhs); + +#else template class SP> inline bool operator!=(const Zbase& lhs, const Zbase& rhs) { return !operator==(lhs, rhs); } template class SP> inline bool operator!=(const Zbase& lhs, const Char* rhs) { return !operator==(lhs, rhs); } template class SP> inline bool operator!=(const Char* lhs, const Zbase& rhs) { return !operator==(lhs, rhs); } @@ -300,6 +314,7 @@ template class SP> inline bool operator!=(const Ch template class SP> bool operator<(const Zbase& lhs, const Zbase& rhs); template class SP> bool operator<(const Zbase& lhs, const Char* rhs); template class SP> bool operator<(const Char* lhs, const Zbase& rhs); +#endif template class SP> inline Zbase operator+(const Zbase& lhs, const Zbase& rhs) { return Zbase(lhs) += rhs; } template class SP> inline Zbase operator+(const Zbase& lhs, const Char* rhs) { return Zbase(lhs) += rhs; } @@ -313,11 +328,6 @@ template class SP> inline Zbase operator template class SP> inline Zbase operator+( Char lhs, const Zbase& rhs) { return Zbase(&lhs, 1) += rhs; } template class SP> inline Zbase operator+(const Char* lhs, const Zbase& rhs) { return Zbase(lhs ) += rhs; } -#if __cpp_impl_three_way_comparison -#error implement: -std::strong_ordering operator<=>(const Zbase& lhs, const Zbase& rhs) -bool operator==(const Zbase& lhs, const Zbase& rhs); -#endif @@ -476,6 +486,31 @@ bool operator==(const Zbase& lhs, const Char* rhs) } +#if __cpp_impl_three_way_comparison && __cpp_lib_three_way_comparison +template class SP> inline +std::strong_ordering operator<=>(const Zbase& lhs, const Zbase& rhs) +{ + return std::lexicographical_compare_three_way(lhs.begin(), lhs.end(), //respect embedded 0 + rhs.begin(), rhs.end()); +} + + +template class SP> inline +std::strong_ordering operator<=>(const Zbase& lhs, const Char* rhs) +{ + return std::lexicographical_compare_three_way(lhs.begin(), lhs.end(), //respect embedded 0 + rhs, rhs + strLength(rhs)); +} + + +template class SP> inline +std::strong_ordering operator<=>(const Char* lhs, const Zbase& rhs) +{ + return std::lexicographical_compare_three_way(lhs, lhs + strLength(lhs), //respect embedded 0 + rhs.begin(), rhs.end()); +} + +#else template class SP> inline bool operator<(const Zbase& lhs, const Zbase& rhs) { @@ -498,6 +533,7 @@ bool operator<(const Char* lhs, const Zbase& rhs) return std::lexicographical_compare(lhs, lhs + strLength(lhs), //respect embedded 0 rhs.begin(), rhs.end()); } +#endif template class SP> inline -- cgit