[libcxx-commits] [libcxx] a4b8ee6 - [libc++] Make MoveOnly constexpr-friendly
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Fri May 22 12:18:21 PDT 2020
Author: Louis Dionne
Date: 2020-05-22T15:18:07-04:00
New Revision: a4b8ee64223f2b942f55237e40e3bd01d9b16893
URL: https://github.com/llvm/llvm-project/commit/a4b8ee64223f2b942f55237e40e3bd01d9b16893
DIFF: https://github.com/llvm/llvm-project/commit/a4b8ee64223f2b942f55237e40e3bd01d9b16893.diff
LOG: [libc++] Make MoveOnly constexpr-friendly
This is necessary when writing constexpr tests.
Added:
Modified:
libcxx/test/support/MoveOnly.h
Removed:
################################################################################
diff --git a/libcxx/test/support/MoveOnly.h b/libcxx/test/support/MoveOnly.h
index 5611ebbdd3a1..f9e9298097f1 100644
--- a/libcxx/test/support/MoveOnly.h
+++ b/libcxx/test/support/MoveOnly.h
@@ -23,18 +23,18 @@ class MoveOnly
int data_;
public:
- MoveOnly(int data = 1) : data_(data) {}
- MoveOnly(MoveOnly&& x)
+ constexpr MoveOnly(int data = 1) : data_(data) {}
+ constexpr MoveOnly(MoveOnly&& x)
: data_(x.data_) {x.data_ = 0;}
- MoveOnly& operator=(MoveOnly&& x)
+ constexpr MoveOnly& operator=(MoveOnly&& x)
{data_ = x.data_; x.data_ = 0; return *this;}
- int get() const {return data_;}
+ constexpr int get() const {return data_;}
- bool operator==(const MoveOnly& x) const {return data_ == x.data_;}
- bool operator< (const MoveOnly& x) const {return data_ < x.data_;}
- MoveOnly operator+(const MoveOnly& x) const { return MoveOnly{data_ + x.data_}; }
- MoveOnly operator*(const MoveOnly& x) const { return MoveOnly{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 MoveOnly operator+(const MoveOnly& x) const { return MoveOnly{data_ + x.data_}; }
+ constexpr MoveOnly operator*(const MoveOnly& x) const { return MoveOnly{data_ * x.data_}; }
};
namespace std {
@@ -44,7 +44,7 @@ struct hash<MoveOnly>
{
typedef MoveOnly argument_type;
typedef size_t result_type;
- std::size_t operator()(const MoveOnly& x) const {return x.get();}
+ constexpr std::size_t operator()(const MoveOnly& x) const {return x.get();}
};
}
More information about the libcxx-commits
mailing list