| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <functional> |
| 10 | |
| 11 | // template<class R, class ...Args> |
| 12 | // function(R(*)(Args...)) -> function<R(Args...)>; |
| 13 | |
| 14 | // UNSUPPORTED: c++03, c++11, c++14 |
| 15 | |
| 16 | #include <functional> |
| 17 | #include <type_traits> |
| 18 | |
| 19 | #include "test_macros.h" |
| 20 | |
| 21 | struct R { }; |
| 22 | struct A1 { }; |
| 23 | struct A2 { }; |
| 24 | struct A3 { }; |
| 25 | |
| 26 | R f0() { return {}; } |
| 27 | R f1(A1) { return {}; } |
| 28 | R f2(A1, A2) { return {}; } |
| 29 | R f3(A1, A2, A3) { return {}; } |
| 30 | R f4(A1 = {}) { return {}; } |
| 31 | |
| 32 | int main(int, char**) { |
| 33 | { |
| 34 | // implicit |
| 35 | std::function a = f0; |
| 36 | ASSERT_SAME_TYPE(decltype(a), std::function<R()>); |
| 37 | |
| 38 | std::function b = &f0; |
| 39 | ASSERT_SAME_TYPE(decltype(b), std::function<R()>); |
| 40 | |
| 41 | // explicit |
| 42 | std::function c{f0}; |
| 43 | ASSERT_SAME_TYPE(decltype(c), std::function<R()>); |
| 44 | |
| 45 | std::function d{&f0}; |
| 46 | ASSERT_SAME_TYPE(decltype(d), std::function<R()>); |
| 47 | } |
| 48 | { |
| 49 | // implicit |
| 50 | std::function a = f1; |
| 51 | ASSERT_SAME_TYPE(decltype(a), std::function<R(A1)>); |
| 52 | |
| 53 | std::function b = &f1; |
| 54 | ASSERT_SAME_TYPE(decltype(b), std::function<R(A1)>); |
| 55 | |
| 56 | // explicit |
| 57 | std::function c{f1}; |
| 58 | ASSERT_SAME_TYPE(decltype(c), std::function<R(A1)>); |
| 59 | |
| 60 | std::function d{&f1}; |
| 61 | ASSERT_SAME_TYPE(decltype(d), std::function<R(A1)>); |
| 62 | } |
| 63 | { |
| 64 | // implicit |
| 65 | std::function a = f2; |
| 66 | ASSERT_SAME_TYPE(decltype(a), std::function<R(A1, A2)>); |
| 67 | |
| 68 | std::function b = &f2; |
| 69 | ASSERT_SAME_TYPE(decltype(b), std::function<R(A1, A2)>); |
| 70 | |
| 71 | // explicit |
| 72 | std::function c{f2}; |
| 73 | ASSERT_SAME_TYPE(decltype(c), std::function<R(A1, A2)>); |
| 74 | |
| 75 | std::function d{&f2}; |
| 76 | ASSERT_SAME_TYPE(decltype(d), std::function<R(A1, A2)>); |
| 77 | } |
| 78 | { |
| 79 | // implicit |
| 80 | std::function a = f3; |
| 81 | ASSERT_SAME_TYPE(decltype(a), std::function<R(A1, A2, A3)>); |
| 82 | |
| 83 | std::function b = &f3; |
| 84 | ASSERT_SAME_TYPE(decltype(b), std::function<R(A1, A2, A3)>); |
| 85 | |
| 86 | // explicit |
| 87 | std::function c{f3}; |
| 88 | ASSERT_SAME_TYPE(decltype(c), std::function<R(A1, A2, A3)>); |
| 89 | |
| 90 | std::function d{&f3}; |
| 91 | ASSERT_SAME_TYPE(decltype(d), std::function<R(A1, A2, A3)>); |
| 92 | } |
| 93 | // Make sure defaulted arguments don't mess up the deduction |
| 94 | { |
| 95 | // implicit |
| 96 | std::function a = f4; |
| 97 | ASSERT_SAME_TYPE(decltype(a), std::function<R(A1)>); |
| 98 | |
| 99 | std::function b = &f4; |
| 100 | ASSERT_SAME_TYPE(decltype(b), std::function<R(A1)>); |
| 101 | |
| 102 | // explicit |
| 103 | std::function c{f4}; |
| 104 | ASSERT_SAME_TYPE(decltype(c), std::function<R(A1)>); |
| 105 | |
| 106 | std::function d{&f4}; |
| 107 | ASSERT_SAME_TYPE(decltype(d), std::function<R(A1)>); |
| 108 | } |
| 109 | |
| 110 | return 0; |
| 111 | } |
| 112 | |