OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef BASE_TEST_COPY_ONLY_INT_H_ |
| 6 #define BASE_TEST_COPY_ONLY_INT_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 |
| 10 namespace base { |
| 11 |
| 12 // A copy-only (not moveable) class that holds an integer. This is designed for |
| 13 // testing containers. See also MoveOnlyInt. |
| 14 class CopyOnlyInt { |
| 15 public: |
| 16 explicit CopyOnlyInt(int data = 1) : data_(data) {} |
| 17 CopyOnlyInt(const CopyOnlyInt& other) : data_(other.data_) {} |
| 18 ~CopyOnlyInt() { data_ = 0; } |
| 19 |
| 20 friend bool operator==(const CopyOnlyInt& lhs, const CopyOnlyInt& rhs) { |
| 21 return lhs.data_ == rhs.data_; |
| 22 } |
| 23 |
| 24 friend bool operator!=(const CopyOnlyInt& lhs, const CopyOnlyInt& rhs) { |
| 25 return !operator==(lhs, rhs); |
| 26 } |
| 27 |
| 28 friend bool operator<(const CopyOnlyInt& lhs, const CopyOnlyInt& rhs) { |
| 29 return lhs.data_ < rhs.data_; |
| 30 } |
| 31 |
| 32 friend bool operator>(const CopyOnlyInt& lhs, const CopyOnlyInt& rhs) { |
| 33 return rhs < lhs; |
| 34 } |
| 35 |
| 36 friend bool operator<=(const CopyOnlyInt& lhs, const CopyOnlyInt& rhs) { |
| 37 return !(rhs < lhs); |
| 38 } |
| 39 |
| 40 friend bool operator>=(const CopyOnlyInt& lhs, const CopyOnlyInt& rhs) { |
| 41 return !(lhs < rhs); |
| 42 } |
| 43 |
| 44 int data() const { return data_; } |
| 45 |
| 46 private: |
| 47 int data_; |
| 48 |
| 49 CopyOnlyInt(CopyOnlyInt&&) = delete; |
| 50 CopyOnlyInt& operator=(CopyOnlyInt&) = delete; |
| 51 }; |
| 52 |
| 53 } // namespace base |
| 54 |
| 55 #endif // BASE_TEST_COPY_ONLY_INT_H_ |
OLD | NEW |