[libcxx-commits] [libcxx] ad4a6ce - [libcxx][test] MoveOnly's comparisons are non-member
Casey Carter via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Jan 28 17:08:54 PST 2021
Author: Casey Carter
Date: 2021-01-28T17:07:03-08:00
New Revision: ad4a6ce10c43d65dd12502bda26dbc983f9bef4e
URL: https://github.com/llvm/llvm-project/commit/ad4a6ce10c43d65dd12502bda26dbc983f9bef4e
DIFF: https://github.com/llvm/llvm-project/commit/ad4a6ce10c43d65dd12502bda26dbc983f9bef4e.diff
LOG: [libcxx][test] MoveOnly's comparisons are non-member
... so that comparisons with an `int` LHS and `MoveOnly` RHS are valid, as is necessary for the `partial_sort_copy` test to pass with an implementation that doesn't force a conversion to the type of the RHS as libc++ does.
Added:
Modified:
libcxx/test/support/MoveOnly.h
Removed:
################################################################################
diff --git a/libcxx/test/support/MoveOnly.h b/libcxx/test/support/MoveOnly.h
index 61eb1902c752..a748ab50bd89 100644
--- a/libcxx/test/support/MoveOnly.h
+++ b/libcxx/test/support/MoveOnly.h
@@ -31,12 +31,19 @@ class MoveOnly
constexpr int get() const {return data_;}
- constexpr bool operator==(const MoveOnly& x) const {return data_ == x.data_;}
- constexpr bool operator!=(const MoveOnly& x) const {return data_ != x.data_;}
- constexpr bool operator< (const MoveOnly& x) const {return data_ < x.data_;}
- constexpr bool operator<=(const MoveOnly& x) const {return data_ <= x.data_;}
- constexpr bool operator> (const MoveOnly& x) const {return data_ > x.data_;}
- constexpr bool operator>=(const MoveOnly& x) const {return data_ >= x.data_;}
+ friend constexpr bool operator==(const MoveOnly& x, const MoveOnly& y)
+ { return x.data_ == y.data_; }
+ friend constexpr bool operator!=(const MoveOnly& x, const MoveOnly& y)
+ { return x.data_ != y.data_; }
+ friend constexpr bool operator< (const MoveOnly& x, const MoveOnly& y)
+ { return x.data_ < y.data_; }
+ friend constexpr bool operator<=(const MoveOnly& x, const MoveOnly& y)
+ { return x.data_ <= y.data_; }
+ friend constexpr bool operator> (const MoveOnly& x, const MoveOnly& y)
+ { return x.data_ > y.data_; }
+ friend constexpr bool operator>=(const MoveOnly& x, const MoveOnly& y)
+ { return x.data_ >= y.data_; }
+
TEST_CONSTEXPR_CXX14 MoveOnly operator+(const MoveOnly& x) const
{ return MoveOnly{data_ + x.data_}; }
TEST_CONSTEXPR_CXX14 MoveOnly operator*(const MoveOnly& x) const
@@ -50,7 +57,7 @@ struct hash<MoveOnly>
{
typedef MoveOnly argument_type;
typedef size_t result_type;
- constexpr std::size_t operator()(const MoveOnly& x) const {return x.get();}
+ constexpr size_t operator()(const MoveOnly& x) const {return x.get();}
};
}
More information about the libcxx-commits
mailing list