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

Side by Side Diff: base/scoped_generic.h

Issue 995093002: Add additional move support to ScopedGeneric in the form of operator=. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 | « no previous file | base/scoped_generic_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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_
OLDNEW
« no previous file with comments | « no previous file | base/scoped_generic_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698