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

Side by Side Diff: base/bind.h

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