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