diff --git a/include/dice/template-library/flex_array.hpp b/include/dice/template-library/flex_array.hpp index 0f5dd48..7fcd6ae 100644 --- a/include/dice/template-library/flex_array.hpp +++ b/include/dice/template-library/flex_array.hpp @@ -25,12 +25,45 @@ namespace dice::template_library { size_t size_ = 0; std::array data_; - constexpr auto operator<=>(flex_array_inner const &other) const noexcept requires (std::three_way_comparable) { - std::span const self_s{data_.data(), size_}; - std::span const other_s{other.data_.data(), other.size_}; + constexpr std::pair, std::span> to_spans(flex_array_inner const &other) const noexcept { + return {std::span{data_.data(), size_}, + std::span{other.data_.data(), other.size_}}; + } + constexpr auto operator<=>(flex_array_inner const &other) const noexcept requires requires (T x) { x <=> x; } { + auto const [self_s, other_s] = to_spans(other); return std::lexicographical_compare_three_way(self_s.begin(), self_s.end(), other_s.begin(), other_s.end()); } + + constexpr bool operator==(flex_array_inner const &other) const noexcept requires requires (T x) { x == x; } { + auto const [self_s, other_s] = to_spans(other); + return std::equal(self_s.begin(), self_s.end(), other_s.begin(), other_s.end()); + } + + constexpr bool operator!=(flex_array_inner const &other) const noexcept requires requires (T x) { x != x; } { + auto const [self_s, other_s] = to_spans(other); + return std::equal(self_s.begin(), self_s.end(), other_s.begin(), other_s.end(), std::not_equal_to{}); + } + + constexpr bool operator<(flex_array_inner const &other) const noexcept requires requires (T x) { x < x; } { + auto const [self_s, other_s] = to_spans(other); + return std::lexicographical_compare(self_s.begin(), self_s.end(), other_s.begin(), other_s.end(), std::less{}); + } + + constexpr bool operator<=(flex_array_inner const &other) const noexcept requires requires (T x) { x <= x; } { + auto const [self_s, other_s] = to_spans(other); + return std::lexicographical_compare(self_s.begin(), self_s.end(), other_s.begin(), other_s.end(), std::less_equal{}); + } + + constexpr bool operator>(flex_array_inner const &other) const noexcept requires requires (T x) { x > x; } { + auto const [self_s, other_s] = to_spans(other); + return std::lexicographical_compare(self_s.begin(), self_s.end(), other_s.begin(), other_s.end(), std::greater{}); + } + + constexpr bool operator>=(flex_array_inner const &other) const noexcept requires requires (T x) { x >= x; } { + auto const [self_s, other_s] = to_spans(other); + return std::lexicographical_compare(self_s.begin(), self_s.end(), other_s.begin(), other_s.end(), std::greater_equal{}); + } }; } // namespace detail_flex_array