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 // https://llvm.org/PR16343
19
20 #include <functional>
21 #include <cassert>
22
23 #include "test_macros.h"
24
25 struct multiply {
26 template <typename T>
operator ()multiply27 TEST_CONSTEXPR_CXX20 T operator()(T a, T b) {
28 return a * b;
29 }
30 };
31
32 struct plus_one {
33 template <typename T>
operator ()plus_one34 TEST_CONSTEXPR_CXX20 T operator()(T a) {
35 return a + 1;
36 }
37 };
38
test()39 TEST_CONSTEXPR_CXX20 bool test() {
40 using std::placeholders::_1;
41 auto g = std::bind(multiply(), 2, _1);
42 assert(g(5) == 10);
43 assert(std::bind(plus_one(), g)(5) == 11);
44
45 return true;
46 }
47
main(int,char **)48 int main(int, char**) {
49 test();
50 #if TEST_STD_VER >= 20
51 static_assert(test());
52 #endif
53
54 return 0;
55 }
56