| OLD | NEW |
| 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 Loading... |
| 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_ |
| OLD | NEW |