Chromium Code Reviews| 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 | 10 |
| 11 #include <stddef.h> | 11 #include <stddef.h> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <type_traits> | 13 #include <type_traits> |
| 14 #include <vector> | |
| 14 | 15 |
| 15 #include "base/atomic_ref_count.h" | 16 #include "base/atomic_ref_count.h" |
| 16 #include "base/base_export.h" | 17 #include "base/base_export.h" |
| 17 #include "base/macros.h" | 18 #include "base/macros.h" |
| 18 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 19 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
| 20 #include "base/template_util.h" | 21 #include "base/template_util.h" |
| 21 | 22 |
| 22 namespace base { | 23 namespace base { |
| 23 namespace internal { | 24 namespace internal { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 template <typename U> | 110 template <typename U> |
| 110 static NoType Test(...); | 111 static NoType Test(...); |
| 111 | 112 |
| 112 static const bool value = sizeof((Test<T>(0))) == sizeof(YesType) && | 113 static const bool value = sizeof((Test<T>(0))) == sizeof(YesType) && |
| 113 !is_const<T>::value; | 114 !is_const<T>::value; |
| 114 }; | 115 }; |
| 115 | 116 |
| 116 // Specialization of IsMoveOnlyType so that std::unique_ptr is still considered | 117 // Specialization of IsMoveOnlyType so that std::unique_ptr is still considered |
| 117 // move-only, even without the sentinel member. | 118 // move-only, even without the sentinel member. |
| 118 template <typename T, typename D> | 119 template <typename T, typename D> |
| 119 struct IsMoveOnlyType<std::unique_ptr<T, D>> : std::true_type {}; | 120 struct IsMoveOnlyType<std::unique_ptr<T, D>> : public std::true_type {}; |
|
danakj
2016/02/02 01:38:34
nit: let's leave out redundant public here and bel
dcheng
2016/02/02 01:52:11
Done.
| |
| 121 | |
| 122 // Specialization of std::vector, so that it's considered move-only if the | |
| 123 // element type is move-only. | |
|
danakj
2016/02/02 01:38:33
Leave a note that it ignores the Allocator?
dcheng
2016/02/02 01:52:11
Done.
| |
| 124 template <typename T, typename Allocator> | |
| 125 struct IsMoveOnlyType<std::vector<T, Allocator>> | |
| 126 : public IsMoveOnlyType<typename std::vector<T, Allocator>::value_type> {}; | |
|
danakj
2016/02/02 01:39:21
vlad's right though that this is the same as
: Is
dcheng
2016/02/02 01:52:11
OK, sure. I had imagined that we could use some ge
| |
| 120 | 127 |
| 121 template <typename> | 128 template <typename> |
| 122 struct CallbackParamTraitsForMoveOnlyType; | 129 struct CallbackParamTraitsForMoveOnlyType; |
| 123 | 130 |
| 124 template <typename> | 131 template <typename> |
| 125 struct CallbackParamTraitsForNonMoveOnlyType; | 132 struct CallbackParamTraitsForNonMoveOnlyType; |
| 126 | 133 |
| 127 // TODO(tzik): Use a default parameter once MSVS supports variadic templates | 134 // TODO(tzik): Use a default parameter once MSVS supports variadic templates |
| 128 // with default values. | 135 // with default values. |
| 129 // http://connect.microsoft.com/VisualStudio/feedbackdetail/view/957801/compilat ion-error-with-variadic-templates | 136 // http://connect.microsoft.com/VisualStudio/feedbackdetail/view/957801/compilat ion-error-with-variadic-templates |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 template <typename T> | 232 template <typename T> |
| 226 typename std::enable_if<IsMoveOnlyType<T>::value, T>::type CallbackForward( | 233 typename std::enable_if<IsMoveOnlyType<T>::value, T>::type CallbackForward( |
| 227 T& t) { | 234 T& t) { |
| 228 return std::move(t); | 235 return std::move(t); |
| 229 } | 236 } |
| 230 | 237 |
| 231 } // namespace internal | 238 } // namespace internal |
| 232 } // namespace base | 239 } // namespace base |
| 233 | 240 |
| 234 #endif // BASE_CALLBACK_INTERNAL_H_ | 241 #endif // BASE_CALLBACK_INTERNAL_H_ |
| OLD | NEW |