Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: base/test/copy_only_int.h

Issue 2898213003: Add skeleton circular queue file.
Patch Set: Fix merge 2 Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/test/BUILD.gn ('k') | base/test/move_only_int.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_
OLDNEW
« no previous file with comments | « base/test/BUILD.gn ('k') | base/test/move_only_int.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698