OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_BIND_H_ | 5 #ifndef BASE_BIND_H_ |
6 #define BASE_BIND_H_ | 6 #define BASE_BIND_H_ |
7 | 7 |
8 #include "base/bind_internal.h" | 8 #include "base/bind_internal.h" |
9 | 9 |
10 // ----------------------------------------------------------------------------- | 10 // ----------------------------------------------------------------------------- |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 namespace internal { | 49 namespace internal { |
50 | 50 |
51 // Don't use Alias Template directly here to avoid a compile error on MSVC2013. | 51 // Don't use Alias Template directly here to avoid a compile error on MSVC2013. |
52 template <typename Functor, typename... Args> | 52 template <typename Functor, typename... Args> |
53 struct MakeUnboundRunTypeImpl { | 53 struct MakeUnboundRunTypeImpl { |
54 using Type = | 54 using Type = |
55 typename BindState< | 55 typename BindState< |
56 typename FunctorTraits<Functor>::RunnableType, | 56 typename FunctorTraits<Functor>::RunnableType, |
57 typename FunctorTraits<Functor>::RunType, | 57 typename FunctorTraits<Functor>::RunType, |
58 typename std::decay<Args>::type...>::UnboundRunType; | 58 Args...>::UnboundRunType; |
59 }; | 59 }; |
60 | 60 |
61 } // namespace internal | 61 } // namespace internal |
62 | 62 |
63 template <typename Functor, typename... Args> | 63 template <typename Functor, typename... Args> |
64 using MakeUnboundRunType = | 64 using MakeUnboundRunType = |
65 typename internal::MakeUnboundRunTypeImpl<Functor, Args...>::Type; | 65 typename internal::MakeUnboundRunTypeImpl<Functor, Args...>::Type; |
66 | 66 |
67 template <typename Functor, typename... Args> | 67 template <typename Functor, typename... Args> |
68 base::Callback<MakeUnboundRunType<Functor, Args...>> | 68 base::Callback<MakeUnboundRunType<Functor, Args...>> |
(...skipping 24 matching lines...) Expand all Loading... |
93 // For methods, we need to be careful for parameter 1. We do not require | 93 // For methods, we need to be careful for parameter 1. We do not require |
94 // a scoped_refptr because BindState<> itself takes care of AddRef() for | 94 // a scoped_refptr because BindState<> itself takes care of AddRef() for |
95 // methods. We also disallow binding of an array as the method's target | 95 // methods. We also disallow binding of an array as the method's target |
96 // object. | 96 // object. |
97 static_assert(!internal::BindsArrayToFirstArg<is_method, Args...>::value, | 97 static_assert(!internal::BindsArrayToFirstArg<is_method, Args...>::value, |
98 "first bound argument to method cannot be array"); | 98 "first bound argument to method cannot be array"); |
99 static_assert( | 99 static_assert( |
100 !internal::HasRefCountedParamAsRawPtr<is_method, Args...>::value, | 100 !internal::HasRefCountedParamAsRawPtr<is_method, Args...>::value, |
101 "a parameter is a refcounted type and needs scoped_refptr"); | 101 "a parameter is a refcounted type and needs scoped_refptr"); |
102 | 102 |
103 using BindState = internal::BindState< | 103 using BindState = internal::BindState<RunnableType, RunType, Args...>; |
104 RunnableType, RunType, typename std::decay<Args>::type...>; | |
105 | 104 |
106 return Callback<typename BindState::UnboundRunType>( | 105 return Callback<typename BindState::UnboundRunType>( |
107 new BindState(internal::MakeRunnable(functor), | 106 new BindState(internal::MakeRunnable(functor), |
108 std::forward<Args>(args)...)); | 107 std::forward<Args>(args)...)); |
109 } | 108 } |
110 | 109 |
111 } // namespace base | 110 } // namespace base |
112 | 111 |
113 #endif // BASE_BIND_H_ | 112 #endif // BASE_BIND_H_ |
OLD | NEW |