OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_SCOPED_GENERIC_H_ | 5 #ifndef BASE_SCOPED_GENERIC_H_ |
6 #define BASE_SCOPED_GENERIC_H_ | 6 #define BASE_SCOPED_GENERIC_H_ |
7 | 7 |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 | 85 |
86 // Move constructor for C++03 move emulation. | 86 // Move constructor for C++03 move emulation. |
87 ScopedGeneric(RValue rvalue) | 87 ScopedGeneric(RValue rvalue) |
88 : data_(rvalue.object->release(), rvalue.object->get_traits()) { | 88 : data_(rvalue.object->release(), rvalue.object->get_traits()) { |
89 } | 89 } |
90 | 90 |
91 ~ScopedGeneric() { | 91 ~ScopedGeneric() { |
92 FreeIfNecessary(); | 92 FreeIfNecessary(); |
93 } | 93 } |
94 | 94 |
95 ScopedGeneric& operator=(ScopedGeneric<T, Traits>&& rhs) { | |
danakj
2015/03/10 20:29:13
If we're going to add rvalue references we should
Robert Sesek
2015/03/10 20:51:15
OK, replaced the emulated move with full C++11 mov
| |
96 reset(rhs.release()); | |
97 return *this; | |
98 } | |
99 | |
95 // Frees the currently owned object, if any. Then takes ownership of a new | 100 // Frees the currently owned object, if any. Then takes ownership of a new |
96 // object, if given. Self-resets are not allowd as on scoped_ptr. See | 101 // object, if given. Self-resets are not allowd as on scoped_ptr. See |
97 // http://crbug.com/162971 | 102 // http://crbug.com/162971 |
98 void reset(const element_type& value = traits_type::InvalidValue()) { | 103 void reset(const element_type& value = traits_type::InvalidValue()) { |
99 if (data_.generic != traits_type::InvalidValue() && data_.generic == value) | 104 if (data_.generic != traits_type::InvalidValue() && data_.generic == value) |
100 abort(); | 105 abort(); |
101 FreeIfNecessary(); | 106 FreeIfNecessary(); |
102 data_.generic = value; | 107 data_.generic = value; |
103 } | 108 } |
104 | 109 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 } | 172 } |
168 | 173 |
169 template<class T, class Traits> | 174 template<class T, class Traits> |
170 bool operator!=(const T& value, const ScopedGeneric<T, Traits>& scoped) { | 175 bool operator!=(const T& value, const ScopedGeneric<T, Traits>& scoped) { |
171 return value != scoped.get(); | 176 return value != scoped.get(); |
172 } | 177 } |
173 | 178 |
174 } // namespace base | 179 } // namespace base |
175 | 180 |
176 #endif // BASE_SCOPED_GENERIC_H_ | 181 #endif // BASE_SCOPED_GENERIC_H_ |
OLD | NEW |