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 #ifndef BASE_TEST_BIND_TEST_UTIL_H_
6 #define BASE_TEST_BIND_TEST_UTIL_H_
7 
8 #include "base/bind.h"
9 
10 namespace base {
11 namespace internal {
12 
13 template <typename F, typename Signature>
14 struct BindLambdaHelper;
15 
16 template <typename F, typename R, typename... Args>
17 struct BindLambdaHelper<F, R(Args...)> {
18   static R Run(const std::decay_t<F>& f, Args... args) {
19     return f(std::forward<Args>(args)...);
20   }
21 };
22 
23 }  // namespace internal
24 
25 // A variant of Bind() that can bind capturing lambdas for testing.
26 // This doesn't support extra arguments binding as the lambda itself can do.
27 template <typename F>
28 decltype(auto) BindLambdaForTesting(F&& f) {
29   using Signature = internal::ExtractCallableRunType<std::decay_t<F>>;
30   return BindRepeating(&internal::BindLambdaHelper<F, Signature>::Run,
31                        std::forward<F>(f));
32 }
33 
34 }  // namespace base
35 
36 #endif  // BASE_TEST_BIND_TEST_UTIL_H_
37