Debian Codegraph @

libstdc++-v3/testsuite/20_util/function/cons/deduction_c++23.cc

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