2 * Copyright 2016 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <folly/Function.h>
22 #include <folly/Memory.h>
23 #include <gtest/gtest.h>
25 using folly::Function;
28 int func_int_int_add_25(int x) {
31 int func_int_int_add_111(int x) {
34 float floatMult(float a, float b) {
38 template <class T, size_t S>
40 std::array<T, S> data = {{0}};
42 // Two operator() with different argument types.
43 // The InvokeReference tests use both
44 T const& operator()(size_t index) const {
47 T operator()(size_t index, T const& value) {
48 T oldvalue = data[index];
54 template <typename Ret, typename... Args>
55 void deduceArgs(Function<Ret(Args...)>) {}
59 // TEST =====================================================================
60 // InvokeFunctor & InvokeReference
62 TEST(Function, InvokeFunctor) {
63 Functor<int, 100> func;
65 sizeof(func) > sizeof(Function<int(size_t)>),
66 "sizeof(Function) is much larger than expected");
69 Function<int(size_t) const> getter = std::move(func);
71 // Function will allocate memory on the heap to store the functor object
72 EXPECT_TRUE(getter.hasAllocatedMemory());
74 EXPECT_EQ(123, getter(5));
77 TEST(Function, InvokeReference) {
78 Functor<int, 10> func;
81 // Have Functions for getter and setter, both referencing the same funtor
82 Function<int(size_t) const> getter = std::ref(func);
83 Function<int(size_t, int)> setter = std::ref(func);
85 EXPECT_EQ(123, getter(5));
86 EXPECT_EQ(123, setter(5, 456));
87 EXPECT_EQ(456, setter(5, 567));
88 EXPECT_EQ(567, getter(5));
91 // TEST =====================================================================
94 TEST(Function, Emptiness_T) {
96 EXPECT_EQ(f, nullptr);
97 EXPECT_EQ(nullptr, f);
99 EXPECT_THROW(f(98), std::bad_function_call);
101 Function<int(int)> g([](int x) { return x + 1; });
102 EXPECT_NE(g, nullptr);
103 EXPECT_NE(nullptr, g);
104 // Explicitly convert to bool to work around
105 // https://github.com/google/googletest/issues/429
106 EXPECT_TRUE(bool(g));
107 EXPECT_EQ(100, g(99));
109 Function<int(int)> h(&func_int_int_add_25);
110 EXPECT_NE(h, nullptr);
111 EXPECT_NE(nullptr, h);
112 EXPECT_TRUE(bool(h));
113 EXPECT_EQ(125, h(100));
116 EXPECT_EQ(h, nullptr);
117 EXPECT_EQ(nullptr, h);
119 EXPECT_THROW(h(101), std::bad_function_call);
122 // TEST =====================================================================
125 template <bool UseSwapMethod>
127 Function<int(int)> mf1(func_int_int_add_25);
128 Function<int(int)> mf2(func_int_int_add_111);
130 EXPECT_EQ(125, mf1(100));
131 EXPECT_EQ(211, mf2(100));
139 EXPECT_EQ(125, mf2(100));
140 EXPECT_EQ(211, mf1(100));
142 Function<int(int)> mf3(nullptr);
143 EXPECT_EQ(mf3, nullptr);
151 EXPECT_EQ(211, mf3(100));
152 EXPECT_EQ(nullptr, mf1);
154 Function<int(int)> mf4([](int x) { return x + 222; });
155 EXPECT_EQ(322, mf4(100));
162 EXPECT_EQ(211, mf4(100));
163 EXPECT_EQ(322, mf3(100));
170 EXPECT_EQ(nullptr, mf3);
171 EXPECT_EQ(322, mf1(100));
173 TEST(Function, SwapMethod) {
176 TEST(Function, SwapFunction) {
180 // TEST =====================================================================
183 TEST(Function, Bind) {
184 Function<float(float, float)> fnc = floatMult;
185 auto task = std::bind(std::move(fnc), 2.f, 4.f);
186 EXPECT_THROW(fnc(0, 0), std::bad_function_call);
187 EXPECT_EQ(8, task());
188 auto task2(std::move(task));
189 EXPECT_THROW(task(), std::bad_function_call);
190 EXPECT_EQ(8, task2());
193 // TEST =====================================================================
196 TEST(Function, NonCopyableLambda) {
197 auto unique_ptr_int = folly::make_unique<int>(900);
198 EXPECT_EQ(900, *unique_ptr_int);
200 char fooData[64] = {0};
201 EXPECT_EQ(0, fooData[0]); // suppress gcc warning about fooData not being used
203 auto functor = std::bind(
204 [fooData](std::unique_ptr<int>& up) mutable { return ++*up; },
205 std::move(unique_ptr_int));
207 EXPECT_EQ(901, functor());
209 Function<int(void)> func = std::move(functor);
210 EXPECT_TRUE(func.hasAllocatedMemory());
212 EXPECT_EQ(902, func());
215 // TEST =====================================================================
218 TEST(Function, OverloadedFunctor) {
219 struct OverloadedFunctor {
221 int operator()(int x) {
225 // variant 2 (const-overload of v1)
226 int operator()(int x) const {
231 int operator()(int x, int) {
235 // variant 4 (const-overload of v3)
236 int operator()(int x, int) const {
240 // variant 5 (non-const, has no const-overload)
241 int operator()(int x, char const*) {
245 // variant 6 (const only)
246 int operator()(int x, std::vector<int> const&) const {
250 OverloadedFunctor of;
252 Function<int(int)> variant1 = of;
253 EXPECT_EQ(100 + 1 * 15, variant1(15));
255 Function<int(int) const> variant2 = of;
256 EXPECT_EQ(100 + 2 * 16, variant2(16));
258 Function<int(int, int)> variant3 = of;
259 EXPECT_EQ(100 + 3 * 17, variant3(17, 0));
261 Function<int(int, int) const> variant4 = of;
262 EXPECT_EQ(100 + 4 * 18, variant4(18, 0));
264 Function<int(int, char const*)> variant5 = of;
265 EXPECT_EQ(100 + 5 * 19, variant5(19, "foo"));
267 Function<int(int, std::vector<int> const&)> variant6 = of;
268 EXPECT_EQ(100 + 6 * 20, variant6(20, {}));
269 EXPECT_EQ(100 + 6 * 20, variant6(20, {1, 2, 3}));
271 Function<int(int, std::vector<int> const&) const> variant6const = of;
272 EXPECT_EQ(100 + 6 * 21, variant6const(21, {}));
274 // Cast const-functions to non-const and the other way around: if the functor
275 // has both const and non-const operator()s for a given parameter signature,
276 // constructing a Function must select one of them, depending on
277 // whether the function type template parameter is const-qualified or not.
278 // When the const-ness is later changed (by moving the
279 // Function<R(Args...)const> into a Function<R(Args...)> or by
280 // calling the folly::constCastFunction which moves it into a
281 // Function<R(Args...)const>), the Function must still execute
282 // the initially selected function.
284 auto variant1_const = folly::constCastFunction(std::move(variant1));
285 EXPECT_THROW(variant1(0), std::bad_function_call);
286 EXPECT_EQ(100 + 1 * 22, variant1_const(22));
288 Function<int(int)> variant2_nonconst = std::move(variant2);
289 EXPECT_THROW(variant2(0), std::bad_function_call);
290 EXPECT_EQ(100 + 2 * 23, variant2_nonconst(23));
292 auto variant3_const = folly::constCastFunction(std::move(variant3));
293 EXPECT_THROW(variant3(0, 0), std::bad_function_call);
294 EXPECT_EQ(100 + 3 * 24, variant3_const(24, 0));
296 Function<int(int, int)> variant4_nonconst = std::move(variant4);
297 EXPECT_THROW(variant4(0, 0), std::bad_function_call);
298 EXPECT_EQ(100 + 4 * 25, variant4_nonconst(25, 0));
300 auto variant5_const = folly::constCastFunction(std::move(variant5));
301 EXPECT_THROW(variant5(0, ""), std::bad_function_call);
302 EXPECT_EQ(100 + 5 * 26, variant5_const(26, "foo"));
304 auto variant6_const = folly::constCastFunction(std::move(variant6));
305 EXPECT_THROW(variant6(0, {}), std::bad_function_call);
306 EXPECT_EQ(100 + 6 * 27, variant6_const(27, {}));
308 Function<int(int, std::vector<int> const&)> variant6const_nonconst =
309 std::move(variant6const);
310 EXPECT_THROW(variant6const(0, {}), std::bad_function_call);
311 EXPECT_EQ(100 + 6 * 28, variant6const_nonconst(28, {}));
314 // TEST =====================================================================
317 TEST(Function, Lambda) {
318 // Non-mutable lambdas: can be stored in a non-const...
319 Function<int(int)> func = [](int x) { return 1000 + x; };
320 EXPECT_EQ(1001, func(1));
322 // ...as well as in a const Function
323 Function<int(int) const> func_const = [](int x) { return 2000 + x; };
324 EXPECT_EQ(2001, func_const(1));
326 // Mutable lambda: can only be stored in a const Function:
328 Function<int()> func_mutable = [number]() mutable { return ++number; };
329 EXPECT_EQ(3001, func_mutable());
330 EXPECT_EQ(3002, func_mutable());
332 // test after const-casting
334 Function<int(int) const> func_made_const =
335 folly::constCastFunction(std::move(func));
336 EXPECT_EQ(1002, func_made_const(2));
337 EXPECT_THROW(func(0), std::bad_function_call);
339 Function<int(int)> func_const_made_nonconst = std::move(func_const);
340 EXPECT_EQ(2002, func_const_made_nonconst(2));
341 EXPECT_THROW(func_const(0), std::bad_function_call);
343 Function<int() const> func_mutable_made_const =
344 folly::constCastFunction(std::move(func_mutable));
345 EXPECT_EQ(3003, func_mutable_made_const());
346 EXPECT_EQ(3004, func_mutable_made_const());
347 EXPECT_THROW(func_mutable(), std::bad_function_call);
350 // TEST =====================================================================
351 // DataMember & MemberFunction
363 TEST(Function, DataMember) {
365 MemberFunc const& cmf = mf;
368 Function<int(MemberFunc const*)> data_getter1 = &MemberFunc::x;
369 EXPECT_EQ(123, data_getter1(&cmf));
370 Function<int(MemberFunc*)> data_getter2 = &MemberFunc::x;
371 EXPECT_EQ(123, data_getter2(&mf));
372 Function<int(MemberFunc const&)> data_getter3 = &MemberFunc::x;
373 EXPECT_EQ(123, data_getter3(cmf));
374 Function<int(MemberFunc&)> data_getter4 = &MemberFunc::x;
375 EXPECT_EQ(123, data_getter4(mf));
378 TEST(Function, MemberFunction) {
380 MemberFunc const& cmf = mf;
383 Function<int(MemberFunc const*)> getter1 = &MemberFunc::getX;
384 EXPECT_EQ(123, getter1(&cmf));
385 Function<int(MemberFunc*)> getter2 = &MemberFunc::getX;
386 EXPECT_EQ(123, getter2(&mf));
387 Function<int(MemberFunc const&)> getter3 = &MemberFunc::getX;
388 EXPECT_EQ(123, getter3(cmf));
389 Function<int(MemberFunc&)> getter4 = &MemberFunc::getX;
390 EXPECT_EQ(123, getter4(mf));
392 Function<void(MemberFunc*, int)> setter1 = &MemberFunc::setX;
394 EXPECT_EQ(234, mf.x);
396 Function<void(MemberFunc&, int)> setter2 = &MemberFunc::setX;
398 EXPECT_EQ(345, mf.x);
401 // TEST =====================================================================
402 // CaptureCopyMoveCount & ParameterCopyMoveCount
404 class CopyMoveTracker {
406 struct ConstructorTag {};
408 CopyMoveTracker() = delete;
409 explicit CopyMoveTracker(ConstructorTag)
410 : data_(std::make_shared<std::pair<size_t, size_t>>(0, 0)) {}
412 CopyMoveTracker(CopyMoveTracker const& o) noexcept : data_(o.data_) {
415 CopyMoveTracker& operator=(CopyMoveTracker const& o) noexcept {
421 CopyMoveTracker(CopyMoveTracker&& o) noexcept : data_(o.data_) {
424 CopyMoveTracker& operator=(CopyMoveTracker&& o) noexcept {
430 size_t copyCount() const {
433 size_t moveCount() const {
434 return data_->second;
436 size_t refCount() const {
437 return data_.use_count();
439 void resetCounters() {
440 data_->first = data_->second = 0;
445 std::shared_ptr<std::pair<size_t, size_t>> data_;
448 TEST(Function, CaptureCopyMoveCount) {
449 // This test checks that no unnecessary copies/moves are made.
451 CopyMoveTracker cmt(CopyMoveTracker::ConstructorTag{});
452 EXPECT_EQ(0, cmt.copyCount());
453 EXPECT_EQ(0, cmt.moveCount());
454 EXPECT_EQ(1, cmt.refCount());
456 // Move into lambda, move lambda into Function
457 auto lambda1 = [cmt = std::move(cmt)]() {
458 return cmt.moveCount();
460 Function<size_t(void)> uf1 = std::move(lambda1);
462 // Max copies: 0. Max copy+moves: 2.
463 EXPECT_LE(cmt.moveCount() + cmt.copyCount(), 2);
464 EXPECT_LE(cmt.copyCount(), 0);
468 // Move into lambda, copy lambda into Function
469 auto lambda2 = [cmt = std::move(cmt)]() {
470 return cmt.moveCount();
472 Function<size_t(void)> uf2 = lambda2;
474 // Max copies: 1. Max copy+moves: 2.
475 EXPECT_LE(cmt.moveCount() + cmt.copyCount(), 2);
476 EXPECT_LE(cmt.copyCount(), 1);
478 // Invoking Function must not make copies/moves of the callable
482 EXPECT_EQ(0, cmt.copyCount());
483 EXPECT_EQ(0, cmt.moveCount());
486 TEST(Function, ParameterCopyMoveCount) {
487 // This test checks that no unnecessary copies/moves are made.
489 CopyMoveTracker cmt(CopyMoveTracker::ConstructorTag{});
490 EXPECT_EQ(0, cmt.copyCount());
491 EXPECT_EQ(0, cmt.moveCount());
492 EXPECT_EQ(1, cmt.refCount());
495 Function<size_t(CopyMoveTracker)> uf1 = [](CopyMoveTracker c) {
496 return c.moveCount();
501 // Max copies: 1. Max copy+moves: 2.
502 EXPECT_LE(cmt.moveCount() + cmt.copyCount(), 2);
503 EXPECT_LE(cmt.copyCount(), 1);
507 // Max copies: 1. Max copy+moves: 2.
508 EXPECT_LE(cmt.moveCount() + cmt.copyCount(), 2);
509 EXPECT_LE(cmt.copyCount(), 0);
512 Function<size_t(CopyMoveTracker&)> uf2 = [](CopyMoveTracker& c) {
513 return c.moveCount();
518 // Max copies: 0. Max copy+moves: 0.
519 EXPECT_LE(cmt.moveCount() + cmt.copyCount(), 0);
520 EXPECT_LE(cmt.copyCount(), 0);
522 // pass by const reference
523 Function<size_t(CopyMoveTracker const&)> uf3 = [](CopyMoveTracker const& c) {
524 return c.moveCount();
529 // Max copies: 0. Max copy+moves: 0.
530 EXPECT_LE(cmt.moveCount() + cmt.copyCount(), 0);
531 EXPECT_LE(cmt.copyCount(), 0);
533 // pass by rvalue reference
534 Function<size_t(CopyMoveTracker &&)> uf4 = [](CopyMoveTracker&& c) {
535 return c.moveCount();
540 // Max copies: 0. Max copy+moves: 0.
541 EXPECT_LE(cmt.moveCount() + cmt.copyCount(), 0);
542 EXPECT_LE(cmt.copyCount(), 0);
545 // TEST =====================================================================
546 // VariadicTemplate & VariadicArguments
548 struct VariadicTemplateSum {
549 int operator()() const {
552 template <class... Args>
553 int operator()(int x, Args... args) const {
554 return x + (*this)(args...);
558 TEST(Function, VariadicTemplate) {
559 Function<int(int)> uf1 = VariadicTemplateSum();
560 Function<int(int, int)> uf2 = VariadicTemplateSum();
561 Function<int(int, int, int)> uf3 = VariadicTemplateSum();
563 EXPECT_EQ(66, uf1(66));
564 EXPECT_EQ(99, uf2(55, 44));
565 EXPECT_EQ(66, uf3(33, 22, 11));
568 struct VariadicArgumentsSum {
569 int operator()(int count, ...) const {
572 va_start(args, count);
573 for (int i = 0; i < count; ++i) {
574 result += va_arg(args, int);
581 TEST(Function, VariadicArguments) {
582 Function<int(int)> uf1 = VariadicArgumentsSum();
583 Function<int(int, int)> uf2 = VariadicArgumentsSum();
584 Function<int(int, int, int)> uf3 = VariadicArgumentsSum();
586 EXPECT_EQ(0, uf1(0));
587 EXPECT_EQ(66, uf2(1, 66));
588 EXPECT_EQ(99, uf3(2, 55, 44));
591 // TEST =====================================================================
592 // SafeCaptureByReference
594 // A function can use Function const& as a parameter to signal that it
595 // is safe to pass a lambda that captures local variables by reference.
596 // It is safe because we know the function called can only invoke the
597 // Function until it returns. It can't store a copy of the Function
598 // (because it's not copyable), and it can't move the Function somewhere
599 // else (because it gets only a const&).
601 template <typename T>
604 Function<void(typename T::value_type const&) const> const& func) {
605 for (auto const& elem : range) {
610 TEST(Function, SafeCaptureByReference) {
611 std::vector<int> const vec = {20, 30, 40, 2, 3, 4, 200, 300, 400};
615 // for_each's second parameter is of type Function<...> const&.
616 // Hence we know we can safely pass it a lambda that references local
617 // variables. There is no way the reference to x will be stored anywhere.
618 for_each<std::vector<int>>(vec, [&sum](int x) { sum += x; });
620 // gcc versions before 4.9 cannot deduce the type T in the above call
621 // to for_each. Modern compiler versions can compile the following line:
622 // for_each(vec, [&sum](int x) { sum += x; });
627 // TEST =====================================================================
630 TEST(Function, IgnoreReturnValue) {
633 // Assign a lambda that return int to a folly::Function that returns void.
634 Function<void()> f = [&]() -> int { return ++x; };
640 Function<int()> g = [&]() -> int { return ++x; };
641 Function<void()> cg = std::move(g);
648 // TEST =====================================================================
649 // ReturnConvertible, ConvertReturnType
651 TEST(Function, ReturnConvertible) {
655 struct CDerived : CBase {};
657 Function<double()> f1 = []() -> int { return 5; };
658 EXPECT_EQ(5.0, f1());
660 Function<int()> f2 = []() -> double { return 5.2; };
666 Function<CBase const&()> f3 = [&]() -> CDerived const& { return derived; };
667 EXPECT_EQ(55, f3().x);
669 Function<CBase const&()> f4 = [&]() -> CDerived& { return derived; };
670 EXPECT_EQ(55, f4().x);
672 Function<CBase&()> f5 = [&]() -> CDerived& { return derived; };
673 EXPECT_EQ(55, f5().x);
675 Function<CBase const*()> f6 = [&]() -> CDerived const* { return &derived; };
676 EXPECT_EQ(f6()->x, 55);
678 Function<CBase const*()> f7 = [&]() -> CDerived* { return &derived; };
679 EXPECT_EQ(55, f7()->x);
681 Function<CBase*()> f8 = [&]() -> CDerived* { return &derived; };
682 EXPECT_EQ(55, f8()->x);
684 Function<CBase()> f9 = [&]() -> CDerived {
689 EXPECT_EQ(66, f9().x);
692 TEST(Function, ConvertReturnType) {
696 struct CDerived : CBase {};
698 Function<int()> f1 = []() -> int { return 5; };
699 Function<double()> cf1 = std::move(f1);
700 EXPECT_EQ(5.0, cf1());
701 Function<int()> ccf1 = std::move(cf1);
702 EXPECT_EQ(5, ccf1());
704 Function<double()> f2 = []() -> double { return 5.2; };
705 Function<int()> cf2 = std::move(f2);
707 Function<double()> ccf2 = std::move(cf2);
708 EXPECT_EQ(5.0, ccf2());
713 Function<CDerived const&()> f3 = [&]() -> CDerived const& { return derived; };
714 Function<CBase const&()> cf3 = std::move(f3);
715 EXPECT_EQ(55, cf3().x);
717 Function<CDerived&()> f4 = [&]() -> CDerived& { return derived; };
718 Function<CBase const&()> cf4 = std::move(f4);
719 EXPECT_EQ(55, cf4().x);
721 Function<CDerived&()> f5 = [&]() -> CDerived& { return derived; };
722 Function<CBase&()> cf5 = std::move(f5);
723 EXPECT_EQ(55, cf5().x);
725 Function<CDerived const*()> f6 = [&]() -> CDerived const* {
728 Function<CBase const*()> cf6 = std::move(f6);
729 EXPECT_EQ(55, cf6()->x);
731 Function<CDerived const*()> f7 = [&]() -> CDerived* { return &derived; };
732 Function<CBase const*()> cf7 = std::move(f7);
733 EXPECT_EQ(55, cf7()->x);
735 Function<CDerived*()> f8 = [&]() -> CDerived* { return &derived; };
736 Function<CBase*()> cf8 = std::move(f8);
737 EXPECT_EQ(55, cf8()->x);
739 Function<CDerived()> f9 = [&]() -> CDerived {
744 Function<CBase()> cf9 = std::move(f9);
745 EXPECT_EQ(66, cf9().x);
748 // TEST =====================================================================
751 TEST(Function, asStdFunction_void) {
753 folly::Function<void()> f = [&] { ++i; };
754 auto sf = std::move(f).asStdFunction();
755 static_assert(std::is_same<decltype(sf), std::function<void()>>::value,
756 "std::function has wrong type");
761 TEST(Function, asStdFunction_void_const) {
763 folly::Function<void() const> f = [&] { ++i; };
764 auto sf = std::move(f).asStdFunction();
765 static_assert(std::is_same<decltype(sf), std::function<void()>>::value,
766 "std::function has wrong type");
771 TEST(Function, asStdFunction_return) {
773 folly::Function<int()> f = [&] {
777 auto sf = std::move(f).asStdFunction();
778 static_assert(std::is_same<decltype(sf), std::function<int()>>::value,
779 "std::function has wrong type");
784 TEST(Function, asStdFunction_return_const) {
786 folly::Function<int() const> f = [&] {
790 auto sf = std::move(f).asStdFunction();
791 static_assert(std::is_same<decltype(sf), std::function<int()>>::value,
792 "std::function has wrong type");
797 TEST(Function, asStdFunction_args) {
799 folly::Function<void(int, int)> f = [&](int x, int y) {
803 auto sf = std::move(f).asStdFunction();
804 static_assert(std::is_same<decltype(sf), std::function<void(int, int)>>::value,
805 "std::function has wrong type");
810 TEST(Function, asStdFunction_args_const) {
812 folly::Function<void(int, int) const> f = [&](int x, int y) {
816 auto sf = std::move(f).asStdFunction();
817 static_assert(std::is_same<decltype(sf), std::function<void(int, int)>>::value,
818 "std::function has wrong type");
823 TEST(Function, NoAllocatedMemoryAfterMove) {
824 Functor<int, 100> foo;
826 Function<int(size_t)> func = foo;
827 EXPECT_TRUE(func.hasAllocatedMemory());
829 Function<int(size_t)> func2 = std::move(func);
830 EXPECT_TRUE(func2.hasAllocatedMemory());
831 EXPECT_FALSE(func.hasAllocatedMemory());
834 TEST(Function, ConstCastEmbedded) {
836 auto functor = [&x]() { ++x; };
838 Function<void() const> func(functor);
839 EXPECT_FALSE(func.hasAllocatedMemory());
841 Function<void()> func2(std::move(func));
842 EXPECT_FALSE(func2.hasAllocatedMemory());
845 TEST(Function, EmptyAfterConstCast) {
846 Function<int(size_t)> func;
849 Function<int(size_t) const> func2 = constCastFunction(std::move(func));
853 TEST(Function, SelfMoveAssign) {
854 Function<int()> f = [] { return 0; };
855 Function<int()>& g = f;
857 EXPECT_TRUE(bool(f));
860 TEST(Function, DeducableArguments) {
861 deduceArgs(Function<void()>{[] {}});
862 deduceArgs(Function<void(int, float)>{[](int, float) {}});
863 deduceArgs(Function<int(int, float)>{[](int i, float) { return i; }});