varasm.c (output_constant): Add new parameter merge_strings.
[official-gcc.git] / libstdc++-v3 / testsuite / 20_util / function / cons / deduction.cc
blob646addf00bf34fe83956e9a7cfba8203d8db8de5
1 // Copyright (C) 2017-2018 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-options "-std=gnu++17" }
19 // { dg-do compile { target c++17 } }
21 #include <functional>
23 template<typename T, typename U> struct require_same;
24 template<typename T> struct require_same<T, T> { using type = void; };
26 template<typename T, typename U>
27 typename require_same<T, U>::type
28 check_type(U&) { }
30 void f0v();
31 void f0vn() noexcept;
32 int f0i();
33 int f0in() noexcept;
34 long f1l(int&);
35 long f1ln(double*) noexcept;
37 void
38 test01()
40 std::function func1 = f0v;
41 check_type<std::function<void()>>(func1);
43 std::function func2 = f0vn;
44 check_type<std::function<void()>>(func2);
46 std::function func3 = f0i;
47 check_type<std::function<int()>>(func3);
49 std::function func4 = f0in;
50 check_type<std::function<int()>>(func4);
52 std::function func5 = f1l;
53 check_type<std::function<long(int&)>>(func5);
55 std::function func6 = f1ln;
56 check_type<std::function<long(double*)>>(func6);
58 std::function func5a = func5;
59 check_type<std::function<long(int&)>>(func5a);
61 std::function func6a = func6;
62 check_type<std::function<long(double*)>>(func6a);
65 struct X {
66 int operator()(const short&, void*);
69 struct Y {
70 void operator()(int) const & noexcept;
73 void
74 test02()
76 X x;
77 std::function func1 = x;
78 check_type<std::function<int(const short&, void*)>>(func1);
80 Y y;
81 std::function func2 = y;
82 check_type<std::function<void(int)>>(func2);
84 std::function func3 = [&x](float) -> X& { return x; };
85 check_type<std::function<X&(float)>>(func3);