Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: base/bind.h

Issue 1507143003: Clean up base::Callback stuff (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/bind_internal.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
10 10
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 // It is possible to move most of the static_assert into BindState<>, but it 44 // It is possible to move most of the static_assert into BindState<>, but it
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> 50 template <typename Functor>
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>::UnboundRunType>
55 internal::TypeList<>>::UnboundRunType>
56 Bind(Functor functor) { 55 Bind(Functor functor) {
57 // Typedefs for how to store and run the functor. 56 // Typedefs for how to store and run the functor.
58 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType; 57 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
59 typedef typename internal::FunctorTraits<Functor>::RunType RunType; 58 typedef typename internal::FunctorTraits<Functor>::RunType RunType;
60 59
61 typedef internal::BindState<RunnableType, RunType, 60 typedef internal::BindState<RunnableType, RunType> BindState;
62 internal::TypeList<>> BindState;
63 61
64 return Callback<typename BindState::UnboundRunType>( 62 return Callback<typename BindState::UnboundRunType>(
65 new BindState(internal::MakeRunnable(functor))); 63 new BindState(internal::MakeRunnable(functor)));
66 } 64 }
67 65
68 template <typename Functor, typename... Args> 66 template <typename Functor, typename... Args>
69 base::Callback< 67 base::Callback<
70 typename internal::BindState< 68 typename internal::BindState<
71 typename internal::FunctorTraits<Functor>::RunnableType, 69 typename internal::FunctorTraits<Functor>::RunnableType,
72 typename internal::FunctorTraits<Functor>::RunType, 70 typename internal::FunctorTraits<Functor>::RunType,
73 internal::TypeList< 71 typename internal::CallbackParamTraits<Args>::StorageType...>
74 typename internal::CallbackParamTraits<Args>::StorageType...>>
75 ::UnboundRunType> 72 ::UnboundRunType>
76 Bind(Functor functor, const Args&... args) { 73 Bind(Functor functor, const Args&... args) {
77 // Typedefs for how to store and run the functor. 74 // Typedefs for how to store and run the functor.
78 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType; 75 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
79 typedef typename internal::FunctorTraits<Functor>::RunType RunType; 76 typedef typename internal::FunctorTraits<Functor>::RunType RunType;
80 77
81 // Use RunnableType::RunType instead of RunType above because our 78 // Use RunnableType::RunType instead of RunType above because our
82 // checks should below for bound references need to know what the actual 79 // checks should below for bound references need to know what the actual
83 // functor is going to interpret the argument as. 80 // functor is going to interpret the argument as.
84 typedef typename RunnableType::RunType BoundRunType; 81 typedef typename RunnableType::RunType BoundRunType;
(...skipping 13 matching lines...) Expand all
98 // 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
99 // object. 96 // object.
100 static_assert(!internal::BindsArrayToFirstArg<is_method, Args...>::value, 97 static_assert(!internal::BindsArrayToFirstArg<is_method, Args...>::value,
101 "first bound argument to method cannot be array"); 98 "first bound argument to method cannot be array");
102 static_assert( 99 static_assert(
103 !internal::HasRefCountedParamAsRawPtr<is_method, Args...>::value, 100 !internal::HasRefCountedParamAsRawPtr<is_method, Args...>::value,
104 "a parameter is a refcounted type and needs scoped_refptr"); 101 "a parameter is a refcounted type and needs scoped_refptr");
105 102
106 typedef internal::BindState< 103 typedef internal::BindState<
107 RunnableType, RunType, 104 RunnableType, RunType,
108 internal::TypeList< 105 typename internal::CallbackParamTraits<Args>::StorageType...>
109 typename internal::CallbackParamTraits<Args>::StorageType...>>
110 BindState; 106 BindState;
111 107
112 return Callback<typename BindState::UnboundRunType>( 108 return Callback<typename BindState::UnboundRunType>(
113 new BindState(internal::MakeRunnable(functor), args...)); 109 new BindState(internal::MakeRunnable(functor), args...));
114 } 110 }
115 111
116 } // namespace base 112 } // namespace base
117 113
118 #endif // BASE_BIND_H_ 114 #endif // BASE_BIND_H_
OLDNEW
« no previous file with comments | « no previous file | base/bind_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698