Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 | 117 |
| 118 // PointerType<T>::type will be scoped_refptr<T> for ref counted types, and T* | 118 // PointerType<T>::type will be scoped_refptr<T> for ref counted types, and T* |
| 119 // otherwise. | 119 // otherwise. |
| 120 template <class T> | 120 template <class T> |
| 121 struct PointerType { | 121 struct PointerType { |
| 122 typedef typename TernaryTypeOperator<IsRefCounted<T>::value, | 122 typedef typename TernaryTypeOperator<IsRefCounted<T>::value, |
| 123 scoped_refptr<T>, | 123 scoped_refptr<T>, |
| 124 T*>::type type; | 124 T*>::type type; |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 // RemoveScopedPtrRef will capture scoped_refptr by-value instead of | 127 // RemoveAllRef implementations are equivalent to std::remove_reference make |
|
magjed_webrtc
2015/10/23 05:17:01
Missing some word or punctuation between 'std::rem
noahric
2015/10/23 06:02:16
Done (no more comment in template_util.h).
| |
| 128 // by-reference. | 128 // sure references and rvalue references are captured by value. |
| 129 template <class T> struct RemoveScopedPtrRef { typedef T type; }; | |
| 130 template <class T> | 129 template <class T> |
| 131 struct RemoveScopedPtrRef<const scoped_refptr<T>&> { | 130 struct RemoveAllRef { |
|
magjed_webrtc
2015/10/23 05:17:01
Can you rename this to rtc::remove_reference and m
noahric
2015/10/23 06:02:16
Done.
| |
| 132 typedef scoped_refptr<T> type; | 131 typedef T type; |
| 133 }; | 132 }; |
| 133 // Remove plain references. | |
| 134 template <class T> | 134 template <class T> |
| 135 struct RemoveScopedPtrRef<scoped_refptr<T>&> { | 135 struct RemoveAllRef<T&> { |
| 136 typedef scoped_refptr<T> type; | 136 typedef T type; |
| 137 }; | |
| 138 // Remove rvalue references. | |
| 139 template <class T> | |
| 140 struct RemoveAllRef<T&&> { | |
| 141 typedef T type; | |
| 137 }; | 142 }; |
| 138 | 143 |
| 139 } // namespace detail | 144 } // namespace detail |
| 140 | 145 |
| 141 $var n = 6 | 146 $var n = 9 |
| 142 $range i 0..n | 147 $range i 0..n |
| 143 $for i [[ | 148 $for i [[ |
| 144 $range j 1..i | 149 $range j 1..i |
| 145 | 150 |
| 146 template <class ObjectT, class MethodT, class R$for j [[, | 151 template <class ObjectT, class MethodT, class R$for j [[, |
| 147 class P$j]]> | 152 class P$j]]> |
| 148 class MethodFunctor$i { | 153 class MethodFunctor$i { |
| 149 public: | 154 public: |
| 150 MethodFunctor$i(MethodT method, ObjectT* object$for j [[, | 155 MethodFunctor$i(MethodT method, ObjectT* object$for j [[, |
| 151 P$j p$j]]) | 156 P$j p$j]]) |
| 152 : method_(method), object_(object)$for j [[, | 157 : method_(method), object_(object)$for j [[, |
| 153 p$(j)_(p$j)]] {} | 158 p$(j)_(p$j)]] {} |
| 154 R operator()() const { | 159 R operator()() const { |
| 155 return (object_->*method_)($for j , [[p$(j)_]]); } | 160 return (object_->*method_)($for j , [[p$(j)_]]); } |
| 156 private: | 161 private: |
| 157 MethodT method_; | 162 MethodT method_; |
| 158 typename detail::PointerType<ObjectT>::type object_;$for j [[ | 163 typename detail::PointerType<ObjectT>::type object_;$for j [[ |
| 159 | 164 |
| 160 typename detail::RemoveScopedPtrRef<P$j>::type p$(j)_;]] | 165 typename detail::RemoveAllRef<P$j>::type p$(j)_;]] |
| 161 | 166 |
| 162 }; | 167 }; |
| 163 | 168 |
| 164 template <class FunctorT, class R$for j [[, | 169 template <class FunctorT, class R$for j [[, |
| 165 class P$j]]> | 170 class P$j]]> |
| 166 class Functor$i { | 171 class Functor$i { |
| 167 public: | 172 public: |
| 168 $if i == 0 [[explicit ]] | 173 $if i == 0 [[explicit ]] |
| 169 Functor$i(const FunctorT& functor$for j [[, P$j p$j]]) | 174 Functor$i(const FunctorT& functor$for j [[, P$j p$j]]) |
| 170 : functor_(functor)$for j [[, | 175 : functor_(functor)$for j [[, |
| 171 p$(j)_(p$j)]] {} | 176 p$(j)_(p$j)]] {} |
| 172 R operator()() const { | 177 R operator()() const { |
| 173 return functor_($for j , [[p$(j)_]]); } | 178 return functor_($for j , [[p$(j)_]]); } |
| 174 private: | 179 private: |
| 175 FunctorT functor_;$for j [[ | 180 FunctorT functor_;$for j [[ |
| 176 | 181 |
| 177 typename detail::RemoveScopedPtrRef<P$j>::type p$(j)_;]] | 182 typename detail::RemoveAllRef<P$j>::type p$(j)_;]] |
| 178 | 183 |
| 179 }; | 184 }; |
| 180 | 185 |
| 181 | 186 |
| 182 #define FP_T(x) R (ObjectT::*x)($for j , [[P$j]]) | 187 #define FP_T(x) R (ObjectT::*x)($for j , [[P$j]]) |
| 183 | 188 |
| 184 template <class ObjectT, class R$for j [[, | 189 template <class ObjectT, class R$for j [[, |
| 185 class P$j]]> | 190 class P$j]]> |
| 186 MethodFunctor$i<ObjectT, FP_T(NONAME), R$for j [[, P$j]]> | 191 MethodFunctor$i<ObjectT, FP_T(NONAME), R$for j [[, P$j]]> |
| 187 Bind(FP_T(method), ObjectT* object$for j [[, | 192 Bind(FP_T(method), ObjectT* object$for j [[, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 | 233 |
| 229 #undef FP_T | 234 #undef FP_T |
| 230 | 235 |
| 231 ]] | 236 ]] |
| 232 | 237 |
| 233 } // namespace rtc | 238 } // namespace rtc |
| 234 | 239 |
| 235 #undef NONAME | 240 #undef NONAME |
| 236 | 241 |
| 237 #endif // WEBRTC_BASE_BIND_H_ | 242 #endif // WEBRTC_BASE_BIND_H_ |
| OLD | NEW |