| 1 | // { dg-do compile { target c++23 } } |
| 2 | |
| 3 | #include <future> |
| 4 | |
| 5 | template<typename T, typename U> struct require_same; |
| 6 | template<typename T> struct require_same<T, T> { using type = void; }; |
| 7 | |
| 8 | template<typename T, typename U> |
| 9 | typename require_same<T, U>::type |
| 10 | check_type(U&) { } |
| 11 | |
| 12 | void |
| 13 | test_static_call_operator() |
| 14 | { |
| 15 | struct F1 { static long operator()() { return 0; } }; |
| 16 | std::packaged_task task1{ F1{} }; |
| 17 | check_type<std::packaged_task<long()>>(task1); |
| 18 | |
| 19 | struct F2 { static float operator()(char, void*) noexcept { return 0; } }; |
| 20 | std::packaged_task task2{ F2{} }; |
| 21 | check_type<std::packaged_task<float(char, void*)>>(task2); |
| 22 | } |
| 23 | |
| 24 | void |
| 25 | test_explicit_object_call_operator() |
| 26 | { |
| 27 | // LWG 3617 - function/packaged_task deduction guides and deducing this |
| 28 | struct F { |
| 29 | int operator()(this const F&) { return 42; } |
| 30 | }; |
| 31 | |
| 32 | std::packaged_task g{ F{} }; |
| 33 | check_type<std::packaged_task<int()>>(g); |
| 34 | |
| 35 | struct F2 { |
| 36 | short operator()(this F2&, float&) { return 0; } |
| 37 | }; |
| 38 | |
| 39 | std::packaged_task g2{ F2{} }; |
| 40 | check_type<std::packaged_task<short(float&)>>(g2); |
| 41 | |
| 42 | struct F3 { |
| 43 | void operator()(this const F3, char*, long) { } |
| 44 | }; |
| 45 | |
| 46 | std::packaged_task g3{ F3{} }; |
| 47 | check_type<std::packaged_task<void(char*, long)>>(g3); |
| 48 | |
| 49 | struct F4 { |
| 50 | int i; |
| 51 | operator const int&() const { return i; } |
| 52 | const long& operator()(this int, const long& l) { return l; } |
| 53 | }; |
| 54 | |
| 55 | std::packaged_task g4{ F4{} }; |
| 56 | check_type<std::packaged_task<const long&(const long&)>>(g4); |
| 57 | } |