// 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. #ifndef TOOLS_CLANG_BASE_BIND_REWRITERS_TESTS_CALLBACK_H_ #define TOOLS_CLANG_BASE_BIND_REWRITERS_TESTS_CALLBACK_H_ #include #include namespace base { namespace internal { template class PassedWrapper { public: explicit PassedWrapper(T&& scoper) {} PassedWrapper(PassedWrapper&& other) {} }; } // namespace internal template ::value>* = nullptr> internal::PassedWrapper Passed(T&& scoper) { return internal::PassedWrapper(std::move(scoper)); } template internal::PassedWrapper Passed(T* scoper) { return internal::PassedWrapper(std::move(*scoper)); } template class OnceCallback; template class RepeatingCallback; template using Callback = RepeatingCallback; using OnceClosure = OnceCallback; using RepeatingClosure = RepeatingCallback; using Closure = Callback; template class OnceCallback { public: OnceCallback() {} OnceCallback(OnceCallback&&) = default; OnceCallback& operator=(OnceCallback&&) = default; OnceCallback(const OnceCallback&) = delete; OnceCallback& operator=(const OnceCallback&) = delete; OnceCallback(RepeatingCallback other) {} OnceCallback& operator=(RepeatingCallback other) { return *this; } R Run(Args... args) const & { static_assert(!sizeof(*this), ""); return R(); } R Run(Args... args) && { return R(); } }; template class RepeatingCallback { public: RepeatingCallback() {} RepeatingCallback(const RepeatingCallback&) = default; RepeatingCallback& operator=(const RepeatingCallback&) = default; RepeatingCallback(RepeatingCallback&&) = default; RepeatingCallback& operator=(RepeatingCallback&&) = default; R Run(Args... args) const & { return R(); } R Run(Args... args) && { return R(); } }; template Callback Bind(Functor, Args&&...) { return Callback(); } template OnceCallback BindOnce(Functor, Args&&...) { return OnceCallback(); } template RepeatingCallback BindRepeating(Functor, Args&&...) { return RepeatingCallback(); } RepeatingCallback AdaptCallbackForRepeating( OnceCallback callback) { return Callback(); } } // namespace base #endif // TOOLS_CLANG_BASE_BIND_REWRITERS_TESTS_CALLBACK_H_