| Index: tools/clang/base_bind_rewriters/tests/test-original.cc
|
| diff --git a/tools/clang/base_bind_rewriters/tests/test-original.cc b/tools/clang/base_bind_rewriters/tests/test-original.cc
|
| index 89acfdeb87e6012bc89d40d4f11e3cd2dd46dfb0..5e92748b0dbf75347df64560f0beae72109ed98b 100644
|
| --- a/tools/clang/base_bind_rewriters/tests/test-original.cc
|
| +++ b/tools/clang/base_bind_rewriters/tests/test-original.cc
|
| @@ -1,37 +1,82 @@
|
| -// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -template <typename>
|
| -class scoped_refptr {
|
| +#include <utility>
|
| +
|
| +namespace base {
|
| +namespace internal {
|
| +
|
| +enum class CopyMode { MoveOnly, Copyable };
|
| +enum class RepeatMode { Once, Repeating };
|
| +
|
| +} // namespace internal
|
| +
|
| +template <typename Signature,
|
| + internal::CopyMode copy_mode = internal::CopyMode::Copyable,
|
| + internal::RepeatMode repeat_mode = internal::RepeatMode::Repeating>
|
| +class Callback;
|
| +
|
| +template <typename Signature>
|
| +using OnceCallback = Callback<Signature,
|
| + internal::CopyMode::MoveOnly,
|
| + internal::RepeatMode::Once>;
|
| +template <typename Signature>
|
| +using RepeatingCallback = Callback<Signature,
|
| + internal::CopyMode::Copyable,
|
| + internal::RepeatMode::Repeating>;
|
| +
|
| +using Closure = Callback<void()>;
|
| +using OnceClosure = OnceCallback<void()>;
|
| +using RepeatingClosure = RepeatingCallback<void()>;
|
| +
|
| +namespace internal {
|
| +
|
| +template <typename From, typename To>
|
| +struct IsCallbackConvertible : std::false_type {};
|
| +
|
| +template <typename Signature>
|
| +struct IsCallbackConvertible<RepeatingCallback<Signature>,
|
| + OnceCallback<Signature>> : std::true_type {};
|
| +
|
| +} // namespace internal
|
| +
|
| +template <typename Signature, internal::CopyMode, internal::RepeatMode>
|
| +class Callback {
|
| public:
|
| - void* get() { return 0; }
|
| + Callback() {}
|
| + Callback(const Callback&) {}
|
| + Callback(Callback&&) {}
|
| +
|
| + template <typename OtherCallback,
|
| + typename = typename std::enable_if<
|
| + internal::IsCallbackConvertible<OtherCallback,
|
| + Callback>::value>::type>
|
| + Callback(OtherCallback other) {}
|
| };
|
|
|
| -namespace base {
|
| +template <typename Functor, typename... Args>
|
| +Callback<void()> Bind(Functor, Args&&...) {
|
| + return Callback<void()>();
|
| +}
|
|
|
| template <typename Functor, typename... Args>
|
| -void Bind(Functor&&, Args&&...) {}
|
| +OnceCallback<void()> BindOnce(Functor, Args&&...) {
|
| + return Callback<void()>();
|
| +}
|
|
|
| } // namespace base
|
|
|
| -struct Foo {
|
| - void Bar();
|
| - static void Baz();
|
| -};
|
| +void foo(base::OnceClosure) {}
|
|
|
| void Test() {
|
| - using base::Bind;
|
| - scoped_refptr<int> foo;
|
| - base::Bind(&Foo::Bar, foo.get());
|
| - Bind(&Foo::Bar, foo.get());
|
| - base::Bind(&Foo::Bar, (&foo)->get());
|
| - base::Bind(&Foo::Bar, foo.get(
|
| - ));
|
| - base::Bind(&Foo::Bar, foo
|
| - .get());
|
| - base::Bind(&Foo::Bar, foo.get(), foo.get());
|
| - base::Bind(&Foo::Baz, foo.get());
|
| - base::Bind(&Foo::Bar, foo.scoped_refptr<int>::get());
|
| - base::Bind(&Foo::Bar, (&foo)->scoped_refptr<int>::get());
|
| + base::OnceClosure cb = base::Bind([] {});
|
| + foo(base::Bind([] {}));
|
| +
|
| + using namespace base;
|
| +
|
| + OnceClosure cb2 = Bind([] {});
|
| + foo(Bind([] {}));
|
| +
|
| + Closure cb3 = base::Bind([] {});
|
| }
|
|
|