diff --git a/xo-allocutil/include/xo/allocutil/gc_ptr.hpp b/xo-allocutil/include/xo/allocutil/gc_ptr.hpp index bb4225ae..a7d09743 100644 --- a/xo-allocutil/include/xo/allocutil/gc_ptr.hpp +++ b/xo-allocutil/include/xo/allocutil/gc_ptr.hpp @@ -69,6 +69,18 @@ namespace xo { T * operator->() const { return ptr_; } T & operator*() const { return *ptr_; } + auto operator<=>(gc_ptr other) const + requires std::three_way_comparable + { + return *ptr_ <=> *other.ptr_; + } + + bool operator==(gc_ptr other) const + requires std::equality_comparable + { + return *ptr_ == *other.ptr_; + } + private: T * ptr_ = nullptr; }; diff --git a/xo-object/include/xo/object/String.hpp b/xo-object/include/xo/object/String.hpp index 7b643574..c5a17122 100644 --- a/xo-object/include/xo/object/String.hpp +++ b/xo-object/include/xo/object/String.hpp @@ -77,6 +77,24 @@ namespace xo { **/ std::size_t columns() const; + std::strong_ordering operator<=>(const String & other) const { + size_t len1 = std::strlen(chars_); + size_t len2 = std::strlen(other.chars_); + + return std::lexicographical_compare_three_way(chars_, chars_ + len1, + other.chars_, other.chars_ + len2); + } + + bool operator==(const String & other) const { + size_t len1 = std::strlen(chars_); + size_t len2 = std::strlen(other.chars_); + + if (len1 != len2) + return false; + + return std::memcmp(chars_, other.chars_, len1) == 0; + } + // inherited from Object.. virtual TaggedPtr self_tp() const final override; virtual void display(std::ostream & os) const final override; @@ -128,6 +146,7 @@ namespace xo { template <> struct ObjectConversion : public ObjectConversion_String {}; + } /*namespace obj*/ } /*namespace xo*/