1*07a0b0eeSArthur O'Dwyer //===----------------------------------------------------------------------===//
2*07a0b0eeSArthur O'Dwyer //
3*07a0b0eeSArthur O'Dwyer // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*07a0b0eeSArthur O'Dwyer // See https://llvm.org/LICENSE.txt for license information.
5*07a0b0eeSArthur O'Dwyer // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*07a0b0eeSArthur O'Dwyer //
7*07a0b0eeSArthur O'Dwyer //===----------------------------------------------------------------------===//
8*07a0b0eeSArthur O'Dwyer 
9*07a0b0eeSArthur O'Dwyer // UNSUPPORTED: c++03, c++11
10*07a0b0eeSArthur O'Dwyer 
11*07a0b0eeSArthur O'Dwyer // <functional>
12*07a0b0eeSArthur O'Dwyer 
13*07a0b0eeSArthur O'Dwyer // template<class T> struct is_bind_expression;
14*07a0b0eeSArthur O'Dwyer //   A program may specialize this template for a program-defined type T
15*07a0b0eeSArthur O'Dwyer //   to have a base characteristic of true_type to indicate that T should
16*07a0b0eeSArthur O'Dwyer //   be treated as a subexpression in a bind call.
17*07a0b0eeSArthur O'Dwyer //   https://llvm.org/PR51753
18*07a0b0eeSArthur O'Dwyer 
19*07a0b0eeSArthur O'Dwyer #include <functional>
20*07a0b0eeSArthur O'Dwyer #include <cassert>
21*07a0b0eeSArthur O'Dwyer #include <type_traits>
22*07a0b0eeSArthur O'Dwyer 
23*07a0b0eeSArthur O'Dwyer struct MyBind {
operator ()MyBind24*07a0b0eeSArthur O'Dwyer     int operator()(int x, int y) const { return 10*x + y; }
25*07a0b0eeSArthur O'Dwyer };
26*07a0b0eeSArthur O'Dwyer template<> struct std::is_bind_expression<MyBind> : std::true_type {};
27*07a0b0eeSArthur O'Dwyer 
main(int,char **)28*07a0b0eeSArthur O'Dwyer int main(int, char**)
29*07a0b0eeSArthur O'Dwyer {
30*07a0b0eeSArthur O'Dwyer   {
31*07a0b0eeSArthur O'Dwyer     auto f = [](auto x) { return 10*x + 9; };
32*07a0b0eeSArthur O'Dwyer     MyBind bindexpr;
33*07a0b0eeSArthur O'Dwyer     auto bound = std::bind(f, bindexpr);
34*07a0b0eeSArthur O'Dwyer     assert(bound(7, 8) == 789);
35*07a0b0eeSArthur O'Dwyer   }
36*07a0b0eeSArthur O'Dwyer   {
37*07a0b0eeSArthur O'Dwyer     auto f = [](auto x) { return 10*x + 9; };
38*07a0b0eeSArthur O'Dwyer     const MyBind bindexpr;
39*07a0b0eeSArthur O'Dwyer     auto bound = std::bind(f, bindexpr);
40*07a0b0eeSArthur O'Dwyer     assert(bound(7, 8) == 789);
41*07a0b0eeSArthur O'Dwyer   }
42*07a0b0eeSArthur O'Dwyer   {
43*07a0b0eeSArthur O'Dwyer     auto f = [](auto x) { return 10*x + 9; };
44*07a0b0eeSArthur O'Dwyer     MyBind bindexpr;
45*07a0b0eeSArthur O'Dwyer     auto bound = std::bind(f, std::move(bindexpr));
46*07a0b0eeSArthur O'Dwyer     assert(bound(7, 8) == 789);
47*07a0b0eeSArthur O'Dwyer   }
48*07a0b0eeSArthur O'Dwyer   {
49*07a0b0eeSArthur O'Dwyer     auto f = [](auto x) { return 10*x + 9; };
50*07a0b0eeSArthur O'Dwyer     const MyBind bindexpr;
51*07a0b0eeSArthur O'Dwyer     auto bound = std::bind(f, std::move(bindexpr));
52*07a0b0eeSArthur O'Dwyer     assert(bound(7, 8) == 789);
53*07a0b0eeSArthur O'Dwyer   }
54*07a0b0eeSArthur O'Dwyer 
55*07a0b0eeSArthur O'Dwyer   return 0;
56*07a0b0eeSArthur O'Dwyer }
57