| 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 28 matching lines...) Expand all Loading... |
| 39 // via an indirection like we do below. | 39 // via an indirection like we do below. |
| 40 // | 40 // |
| 41 // TODO(ajwong): We might be able to avoid this now, but need to test. | 41 // TODO(ajwong): We might be able to avoid this now, but need to test. |
| 42 // | 42 // |
| 43 // It is possible to move most of the static_assert into BindState<>, but it | 43 // It is possible to move most of the static_assert into BindState<>, but it |
| 44 // 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 |
| 45 // 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. |
| 46 | 46 |
| 47 namespace base { | 47 namespace base { |
| 48 | 48 |
| 49 namespace internal { |
| 50 |
| 51 // Don't use Alias Template directly here to avoid a compile error on MSVC2013. |
| 49 template <typename Functor, typename... Args> | 52 template <typename Functor, typename... Args> |
| 50 base::Callback< | 53 struct MakeUnboundRunTypeImpl { |
| 51 typename internal::BindState< | 54 using Type = |
| 52 typename internal::FunctorTraits<Functor>::RunnableType, | 55 typename BindState< |
| 53 typename internal::FunctorTraits<Functor>::RunType, | 56 typename FunctorTraits<Functor>::RunnableType, |
| 54 typename std::decay<Args>::type...>::UnboundRunType> | 57 typename FunctorTraits<Functor>::RunType, |
| 58 typename std::decay<Args>::type...>::UnboundRunType; |
| 59 }; |
| 60 |
| 61 } // namespace internal |
| 62 |
| 63 template <typename Functor, typename... Args> |
| 64 using MakeUnboundRunType = |
| 65 typename internal::MakeUnboundRunTypeImpl<Functor, Args...>::Type; |
| 66 |
| 67 template <typename Functor, typename... Args> |
| 68 base::Callback<MakeUnboundRunType<Functor, Args...>> |
| 55 Bind(Functor functor, Args&&... args) { | 69 Bind(Functor functor, Args&&... args) { |
| 56 // Type aliases for how to store and run the functor. | 70 // Type aliases for how to store and run the functor. |
| 57 using RunnableType = typename internal::FunctorTraits<Functor>::RunnableType; | 71 using RunnableType = typename internal::FunctorTraits<Functor>::RunnableType; |
| 58 using RunType = typename internal::FunctorTraits<Functor>::RunType; | 72 using RunType = typename internal::FunctorTraits<Functor>::RunType; |
| 59 | 73 |
| 60 // Use RunnableType::RunType instead of RunType above because our | 74 // Use RunnableType::RunType instead of RunType above because our |
| 61 // checks below for bound references need to know what the actual | 75 // checks below for bound references need to know what the actual |
| 62 // functor is going to interpret the argument as. | 76 // functor is going to interpret the argument as. |
| 63 using BoundRunType = typename RunnableType::RunType; | 77 using BoundRunType = typename RunnableType::RunType; |
| 64 | 78 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 90 RunnableType, RunType, typename std::decay<Args>::type...>; | 104 RunnableType, RunType, typename std::decay<Args>::type...>; |
| 91 | 105 |
| 92 return Callback<typename BindState::UnboundRunType>( | 106 return Callback<typename BindState::UnboundRunType>( |
| 93 new BindState(internal::MakeRunnable(functor), | 107 new BindState(internal::MakeRunnable(functor), |
| 94 std::forward<Args>(args)...)); | 108 std::forward<Args>(args)...)); |
| 95 } | 109 } |
| 96 | 110 |
| 97 } // namespace base | 111 } // namespace base |
| 98 | 112 |
| 99 #endif // BASE_BIND_H_ | 113 #endif // BASE_BIND_H_ |
| OLD | NEW |