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

Side by Side Diff: mojo/public/cpp/bindings/callback.h

Issue 1395533005: Use <type_traits> in the C++ bindings library wherever possible. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 2 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 | mojo/public/cpp/bindings/lib/array_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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 MOJO_PUBLIC_CPP_BINDINGS_CALLBACK_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_CALLBACK_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_CALLBACK_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_CALLBACK_H_
7 7
8 #include <type_traits>
9
8 #include "mojo/public/cpp/bindings/lib/callback_internal.h" 10 #include "mojo/public/cpp/bindings/lib/callback_internal.h"
9 #include "mojo/public/cpp/bindings/lib/shared_ptr.h" 11 #include "mojo/public/cpp/bindings/lib/shared_ptr.h"
10 #include "mojo/public/cpp/bindings/lib/template_util.h" 12 #include "mojo/public/cpp/bindings/lib/template_util.h"
11 13
12 namespace mojo { 14 namespace mojo {
13 15
14 template <typename Sig> 16 template <typename Sig>
15 class Callback; 17 class Callback;
16 18
17 // Represents a callback with any number of parameters and no return value. The 19 // Represents a callback with any number of parameters and no return value. The
(...skipping 16 matching lines...) Expand all
34 36
35 // Constructs a callback that will run |runnable|. The callback takes 37 // Constructs a callback that will run |runnable|. The callback takes
36 // ownership of |runnable|. 38 // ownership of |runnable|.
37 explicit Callback(Runnable* runnable) : sink_(runnable) {} 39 explicit Callback(Runnable* runnable) : sink_(runnable) {}
38 40
39 // As above, but can take an object that isn't derived from Runnable, so long 41 // As above, but can take an object that isn't derived from Runnable, so long
40 // as it has a compatible operator() or Run() method. operator() will be 42 // as it has a compatible operator() or Run() method. operator() will be
41 // preferred if the type has both. 43 // preferred if the type has both.
42 template <typename Sink> 44 template <typename Sink>
43 Callback(const Sink& sink) { 45 Callback(const Sink& sink) {
44 using sink_type = typename internal::Conditional< 46 using sink_type = typename std::conditional<
45 internal::HasCompatibleCallOperator<Sink, Args...>::value, 47 internal::HasCompatibleCallOperator<Sink, Args...>::value,
46 FunctorAdapter<Sink>, RunnableAdapter<Sink>>::type; 48 FunctorAdapter<Sink>, RunnableAdapter<Sink>>::type;
47 sink_ = internal::SharedPtr<Runnable>(new sink_type(sink)); 49 sink_ = internal::SharedPtr<Runnable>(new sink_type(sink));
48 } 50 }
49 51
50 // As above, but can take a compatible function pointer. 52 // As above, but can take a compatible function pointer.
51 Callback(void (*function_ptr)( 53 Callback(void (*function_ptr)(
52 typename internal::Callback_ParamTraits<Args>::ForwardType...)) 54 typename internal::Callback_ParamTraits<Args>::ForwardType...))
53 : sink_(new FunctionPtrAdapter(function_ptr)) {} 55 : sink_(new FunctionPtrAdapter(function_ptr)) {}
54 56
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 108
107 internal::SharedPtr<Runnable> sink_; 109 internal::SharedPtr<Runnable> sink_;
108 }; 110 };
109 111
110 // A specialization of Callback which takes no parameters. 112 // A specialization of Callback which takes no parameters.
111 typedef Callback<void()> Closure; 113 typedef Callback<void()> Closure;
112 114
113 } // namespace mojo 115 } // namespace mojo
114 116
115 #endif // MOJO_PUBLIC_CPP_BINDINGS_CALLBACK_H_ 117 #endif // MOJO_PUBLIC_CPP_BINDINGS_CALLBACK_H_
OLDNEW
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/lib/array_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698