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 <cassert>
20#include <functional>
21#include <type_traits>
22#include <utility>
23
24struct MyBind {
25 int operator()(int x, int y) const { return 10*x + y; }
26};
27template<> struct std::is_bind_expression<MyBind> : std::true_type {};
28
29int main(int, char**)
30{
31 {
32 auto f = [](auto x) { return 10*x + 9; };
33 MyBind bindexpr;
34 auto bound = std::bind(f&: f, args&: bindexpr);
35 assert(bound(7, 8) == 789);
36 }
37 {
38 auto f = [](auto x) { return 10*x + 9; };
39 const MyBind bindexpr;
40 auto bound = std::bind(f&: f, args: bindexpr);
41 assert(bound(7, 8) == 789);
42 }
43 {
44 auto f = [](auto x) { return 10*x + 9; };
45 MyBind bindexpr;
46 auto bound = std::bind(f&: f, args: std::move(bindexpr));
47 assert(bound(7, 8) == 789);
48 }
49 {
50 auto f = [](auto x) { return 10*x + 9; };
51 const MyBind bindexpr;
52 auto bound = std::bind(f&: f, args: std::move(bindexpr));
53 assert(bound(7, 8) == 789);
54 }
55
56 return 0;
57}
58

source code of libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.isbind/specialization.pass.cpp