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 | // UNSUPPORTED: c++03 |
10 | |
11 | // <functional> |
12 | |
13 | // template<CopyConstructible Fn, CopyConstructible... Types> |
14 | // unspecified bind(Fn, Types...); // constexpr since C++20 |
15 | // template<Returnable R, CopyConstructible Fn, CopyConstructible... Types> |
16 | // unspecified bind(Fn, Types...); // constexpr since C++20 |
17 | |
18 | #include <functional> |
19 | #include <cassert> |
20 | |
21 | #include "test_macros.h" |
22 | |
23 | template <class R, class F> |
24 | TEST_CONSTEXPR_CXX20 |
25 | void test(F f, R expected) { |
26 | assert(f() == expected); |
27 | } |
28 | |
29 | template <class R, class F> |
30 | TEST_CONSTEXPR_CXX20 |
31 | void test_const(const F& f, R expected) { |
32 | assert(f() == expected); |
33 | } |
34 | |
35 | TEST_CONSTEXPR_CXX20 int f() {return 1;} |
36 | |
37 | struct A_int_0 { |
38 | TEST_CONSTEXPR_CXX20 int operator()() {return 4;} |
39 | TEST_CONSTEXPR_CXX20 int operator()() const {return 5;} |
40 | }; |
41 | |
42 | TEST_CONSTEXPR_CXX20 bool test_all() { |
43 | test(std::bind(f), 1); |
44 | test(std::bind(&f), 1); |
45 | test(std::bind(f: A_int_0()), 4); |
46 | test_const(std::bind(f: A_int_0()), 5); |
47 | |
48 | test(std::bind<int>(f), 1); |
49 | test(std::bind<int>(&f), 1); |
50 | test(std::bind<int>(f: A_int_0()), 4); |
51 | test_const(std::bind<int>(f: A_int_0()), 5); |
52 | return true; |
53 | } |
54 | |
55 | int main(int, char**) { |
56 | test_all(); |
57 | #if TEST_STD_VER >= 20 |
58 | static_assert(test_all()); |
59 | #endif |
60 | |
61 | return 0; |
62 | } |
63 | |