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

Side by Side Diff: tools/clang/base_bind_rewriters/tests/callback.h

Issue 2789153002: Update BaseBindRewriters to convert base::Bind to base::BindOnce (Closed)
Patch Set: rename test files Created 3 years, 8 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
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <utility>
6
7 namespace base {
8 namespace internal {
9
10 enum class CopyMode { MoveOnly, Copyable };
11 enum class RepeatMode { Once, Repeating };
12
13 } // namespace internal
14
15 template <typename Signature,
16 internal::CopyMode copy_mode = internal::CopyMode::Copyable,
17 internal::RepeatMode repeat_mode = internal::RepeatMode::Repeating>
18 class Callback;
19
20 template <typename Signature>
21 using OnceCallback = Callback<Signature,
22 internal::CopyMode::MoveOnly,
23 internal::RepeatMode::Once>;
24 template <typename Signature>
25 using RepeatingCallback = Callback<Signature,
26 internal::CopyMode::Copyable,
27 internal::RepeatMode::Repeating>;
28
29 using Closure = Callback<void()>;
30 using OnceClosure = OnceCallback<void()>;
31 using RepeatingClosure = RepeatingCallback<void()>;
32
33 namespace internal {
34
35 template <typename From, typename To>
36 struct IsCallbackConvertible : std::false_type {};
37
38 template <typename Signature>
39 struct IsCallbackConvertible<RepeatingCallback<Signature>,
40 OnceCallback<Signature>> : std::true_type {};
41
42 } // namespace internal
43
44 template <typename Signature, internal::CopyMode, internal::RepeatMode>
45 class Callback {
46 public:
47 Callback() {}
48 Callback(const Callback&) {}
49 Callback(Callback&&) {}
50
51 template <typename OtherCallback,
52 typename = typename std::enable_if<
53 internal::IsCallbackConvertible<OtherCallback,
54 Callback>::value>::type>
55 Callback(OtherCallback other) {}
56 };
57
58 template <typename Functor, typename... Args>
59 Callback<void()> Bind(Functor, Args&&...) {
60 return Callback<void()>();
61 }
62
63 template <typename Functor, typename... Args>
64 OnceCallback<void()> BindOnce(Functor, Args&&...) {
65 return Callback<void()>();
66 }
67
68 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698