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

Side by Side Diff: base/callback_internal.h

Issue 10344012: For types that support Pass(), e.g. scoped_ptr and friends, use Passed in PostTaskAndReplyWithResul… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 8 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | base/task_runner_util.h » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // This file contains utility functions and classes that help the 5 // This file contains utility functions and classes that help the
6 // implementation, and management of the Callback objects. 6 // implementation, and management of the Callback objects.
7 7
8 #ifndef BASE_CALLBACK_INTERNAL_H_ 8 #ifndef BASE_CALLBACK_INTERNAL_H_
9 #define BASE_CALLBACK_INTERNAL_H_ 9 #define BASE_CALLBACK_INTERNAL_H_
10 #pragma once 10 #pragma once
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 // used by the Callback/Bind system for a set of movable-but-not-copyable 159 // used by the Callback/Bind system for a set of movable-but-not-copyable
160 // types. It is needed because forwarding a movable-but-not-copyable 160 // types. It is needed because forwarding a movable-but-not-copyable
161 // argument to another function requires us to invoke the proper move 161 // argument to another function requires us to invoke the proper move
162 // operator to create a rvalue version of the type. The supported types are 162 // operator to create a rvalue version of the type. The supported types are
163 // whitelisted below as overloads of the CallbackForward() function. The 163 // whitelisted below as overloads of the CallbackForward() function. The
164 // default template compiles out to be a no-op. 164 // default template compiles out to be a no-op.
165 // 165 //
166 // In C++11, std::forward would replace all uses of this function. However, it 166 // In C++11, std::forward would replace all uses of this function. However, it
167 // is impossible to implement a general std::forward with C++11 due to a lack 167 // is impossible to implement a general std::forward with C++11 due to a lack
168 // of rvalue references. 168 // of rvalue references.
169 //
170 // In addition to Callback/Bind, this is used by PostTaskAndReplyWithResult to
171 // simulate std::forward() and forward the result of one Callback as a
172 // parameter to another callback. This is to support Callbacks that return
173 // the movable-but-not-copyable types whitelisted above.
169 template <typename T> 174 template <typename T>
170 T& CallbackForward(T& t) { return t; } 175 T& CallbackForward(T& t) { return t; }
171 176
172 template <typename T> 177 template <typename T>
173 scoped_ptr<T> CallbackForward(scoped_ptr<T>& p) { return p.Pass(); } 178 scoped_ptr<T> CallbackForward(scoped_ptr<T>& p) { return p.Pass(); }
174 179
175 template <typename T> 180 template <typename T>
176 scoped_array<T> CallbackForward(scoped_array<T>& p) { return p.Pass(); } 181 scoped_array<T> CallbackForward(scoped_array<T>& p) { return p.Pass(); }
177 182
178 template <typename T> 183 template <typename T>
179 scoped_ptr_malloc<T> CallbackForward(scoped_ptr_malloc<T>& p) { 184 scoped_ptr_malloc<T> CallbackForward(scoped_ptr_malloc<T>& p) {
180 return p.Pass(); 185 return p.Pass();
181 } 186 }
182 187
183 template <typename T> 188 template <typename T>
184 ScopedVector<T> CallbackForward(ScopedVector<T>& p) { return p.Pass(); } 189 ScopedVector<T> CallbackForward(ScopedVector<T>& p) { return p.Pass(); }
185 190
186 } // namespace internal 191 } // namespace internal
187 } // namespace base 192 } // namespace base
188 193
189 #endif // BASE_CALLBACK_INTERNAL_H_ 194 #endif // BASE_CALLBACK_INTERNAL_H_
OLDNEW
« no previous file with comments | « no previous file | base/task_runner_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698