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 #include "base/callback_internal.h" | 9 #include "base/callback_internal.h" |
danakj
2016/01/28 23:01:00
Should this be removed? (bind_internal.h still use
tzik
2016/02/01 15:00:16
Done.
| |
10 | 10 |
11 // ----------------------------------------------------------------------------- | 11 // ----------------------------------------------------------------------------- |
12 // Usage documentation | 12 // Usage documentation |
13 // ----------------------------------------------------------------------------- | 13 // ----------------------------------------------------------------------------- |
14 // | 14 // |
15 // See base/callback.h for documentation. | 15 // See base/callback.h for documentation. |
16 // | 16 // |
17 // | 17 // |
18 // ----------------------------------------------------------------------------- | 18 // ----------------------------------------------------------------------------- |
19 // Implementation notes | 19 // Implementation notes |
(...skipping 25 matching lines...) Expand all Loading... | |
45 // feels a little nicer to have the asserts here so people do not need to crack | 45 // feels a little nicer to have the asserts here so people do not need to crack |
46 // open bind_internal.h. On the other hand, it makes Bind() harder to read. | 46 // open bind_internal.h. On the other hand, it makes Bind() harder to read. |
47 | 47 |
48 namespace base { | 48 namespace base { |
49 | 49 |
50 template <typename Functor, typename... Args> | 50 template <typename Functor, typename... Args> |
51 base::Callback< | 51 base::Callback< |
52 typename internal::BindState< | 52 typename internal::BindState< |
53 typename internal::FunctorTraits<Functor>::RunnableType, | 53 typename internal::FunctorTraits<Functor>::RunnableType, |
54 typename internal::FunctorTraits<Functor>::RunType, | 54 typename internal::FunctorTraits<Functor>::RunType, |
55 typename internal::CallbackParamTraits<Args>::StorageType...> | 55 typename std::decay<Args>::type...>::UnboundRunType> |
56 ::UnboundRunType> | 56 Bind(Functor functor, Args&&... args) { |
57 Bind(Functor functor, const Args&... args) { | |
58 // Type aliases for how to store and run the functor. | 57 // Type aliases for how to store and run the functor. |
59 using RunnableType = typename internal::FunctorTraits<Functor>::RunnableType; | 58 using RunnableType = typename internal::FunctorTraits<Functor>::RunnableType; |
60 using RunType = typename internal::FunctorTraits<Functor>::RunType; | 59 using RunType = typename internal::FunctorTraits<Functor>::RunType; |
61 | 60 |
62 // Use RunnableType::RunType instead of RunType above because our | 61 // Use RunnableType::RunType instead of RunType above because our |
63 // checks below for bound references need to know what the actual | 62 // checks below for bound references need to know what the actual |
64 // functor is going to interpret the argument as. | 63 // functor is going to interpret the argument as. |
65 using BoundRunType = typename RunnableType::RunType; | 64 using BoundRunType = typename RunnableType::RunType; |
66 | 65 |
67 using BoundArgs = | 66 using BoundArgs = |
(...skipping 14 matching lines...) Expand all Loading... | |
82 // a scoped_refptr because BindState<> itself takes care of AddRef() for | 81 // a scoped_refptr because BindState<> itself takes care of AddRef() for |
83 // methods. We also disallow binding of an array as the method's target | 82 // methods. We also disallow binding of an array as the method's target |
84 // object. | 83 // object. |
85 static_assert(!internal::BindsArrayToFirstArg<is_method, Args...>::value, | 84 static_assert(!internal::BindsArrayToFirstArg<is_method, Args...>::value, |
86 "first bound argument to method cannot be array"); | 85 "first bound argument to method cannot be array"); |
87 static_assert( | 86 static_assert( |
88 !internal::HasRefCountedParamAsRawPtr<is_method, Args...>::value, | 87 !internal::HasRefCountedParamAsRawPtr<is_method, Args...>::value, |
89 "a parameter is a refcounted type and needs scoped_refptr"); | 88 "a parameter is a refcounted type and needs scoped_refptr"); |
90 | 89 |
91 using BindState = internal::BindState< | 90 using BindState = internal::BindState< |
92 RunnableType, RunType, | 91 RunnableType, RunType, typename std::decay<Args>::type...>; |
93 typename internal::CallbackParamTraits<Args>::StorageType...>; | |
94 | 92 |
95 return Callback<typename BindState::UnboundRunType>( | 93 return Callback<typename BindState::UnboundRunType>( |
96 new BindState(internal::MakeRunnable(functor), args...)); | 94 new BindState(internal::MakeRunnable(functor), |
95 std::forward<Args>(args)...)); | |
97 } | 96 } |
98 | 97 |
99 } // namespace base | 98 } // namespace base |
100 | 99 |
101 #endif // BASE_BIND_H_ | 100 #endif // BASE_BIND_H_ |
OLD | NEW |