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, c++11
10
11 // <functional>
12
13 // template<class T> struct is_bind_expression;
14 // A program may specialize this template for a program-defined type T
15 // to have a base characteristic of true_type to indicate that T should
16 // be treated as a subexpression in a bind call.
17 // https://llvm.org/PR51753
18
19 #include <functional>
20 #include <cassert>
21 #include <type_traits>
22
23 struct MyBind {
operator ()MyBind24 int operator()(int x, int y) const { return 10*x + y; }
25 };
26 template<> struct std::is_bind_expression<MyBind> : std::true_type {};
27
main(int,char **)28 int main(int, char**)
29 {
30 {
31 auto f = [](auto x) { return 10*x + 9; };
32 MyBind bindexpr;
33 auto bound = std::bind(f, bindexpr);
34 assert(bound(7, 8) == 789);
35 }
36 {
37 auto f = [](auto x) { return 10*x + 9; };
38 const MyBind bindexpr;
39 auto bound = std::bind(f, bindexpr);
40 assert(bound(7, 8) == 789);
41 }
42 {
43 auto f = [](auto x) { return 10*x + 9; };
44 MyBind bindexpr;
45 auto bound = std::bind(f, std::move(bindexpr));
46 assert(bound(7, 8) == 789);
47 }
48 {
49 auto f = [](auto x) { return 10*x + 9; };
50 const MyBind bindexpr;
51 auto bound = std::bind(f, std::move(bindexpr));
52 assert(bound(7, 8) == 789);
53 }
54
55 return 0;
56 }
57