107a0b0eeSArthur O'Dwyer //===----------------------------------------------------------------------===//
207a0b0eeSArthur O'Dwyer //
307a0b0eeSArthur O'Dwyer // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
407a0b0eeSArthur O'Dwyer // See https://llvm.org/LICENSE.txt for license information.
507a0b0eeSArthur O'Dwyer // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
607a0b0eeSArthur O'Dwyer //
707a0b0eeSArthur O'Dwyer //===----------------------------------------------------------------------===//
807a0b0eeSArthur O'Dwyer 
907a0b0eeSArthur O'Dwyer // UNSUPPORTED: c++03, c++11
1007a0b0eeSArthur O'Dwyer 
1107a0b0eeSArthur O'Dwyer // <functional>
1207a0b0eeSArthur O'Dwyer 
1307a0b0eeSArthur O'Dwyer // template<class T> struct is_bind_expression;
1407a0b0eeSArthur O'Dwyer //   A program may specialize this template for a program-defined type T
1507a0b0eeSArthur O'Dwyer //   to have a base characteristic of true_type to indicate that T should
1607a0b0eeSArthur O'Dwyer //   be treated as a subexpression in a bind call.
1707a0b0eeSArthur O'Dwyer //   https://llvm.org/PR51753
1807a0b0eeSArthur O'Dwyer 
1907a0b0eeSArthur O'Dwyer #include <cassert>
20*7afa1598SNikolas Klauser #include <functional>
2107a0b0eeSArthur O'Dwyer #include <type_traits>
22*7afa1598SNikolas Klauser #include <utility>
2307a0b0eeSArthur O'Dwyer 
2407a0b0eeSArthur O'Dwyer struct MyBind {
operator ()MyBind2507a0b0eeSArthur O'Dwyer     int operator()(int x, int y) const { return 10*x + y; }
2607a0b0eeSArthur O'Dwyer };
2707a0b0eeSArthur O'Dwyer template<> struct std::is_bind_expression<MyBind> : std::true_type {};
2807a0b0eeSArthur O'Dwyer 
main(int,char **)2907a0b0eeSArthur O'Dwyer int main(int, char**)
3007a0b0eeSArthur O'Dwyer {
3107a0b0eeSArthur O'Dwyer   {
3207a0b0eeSArthur O'Dwyer     auto f = [](auto x) { return 10*x + 9; };
3307a0b0eeSArthur O'Dwyer     MyBind bindexpr;
3407a0b0eeSArthur O'Dwyer     auto bound = std::bind(f, bindexpr);
3507a0b0eeSArthur O'Dwyer     assert(bound(7, 8) == 789);
3607a0b0eeSArthur O'Dwyer   }
3707a0b0eeSArthur O'Dwyer   {
3807a0b0eeSArthur O'Dwyer     auto f = [](auto x) { return 10*x + 9; };
3907a0b0eeSArthur O'Dwyer     const MyBind bindexpr;
4007a0b0eeSArthur O'Dwyer     auto bound = std::bind(f, bindexpr);
4107a0b0eeSArthur O'Dwyer     assert(bound(7, 8) == 789);
4207a0b0eeSArthur O'Dwyer   }
4307a0b0eeSArthur O'Dwyer   {
4407a0b0eeSArthur O'Dwyer     auto f = [](auto x) { return 10*x + 9; };
4507a0b0eeSArthur O'Dwyer     MyBind bindexpr;
4607a0b0eeSArthur O'Dwyer     auto bound = std::bind(f, std::move(bindexpr));
4707a0b0eeSArthur O'Dwyer     assert(bound(7, 8) == 789);
4807a0b0eeSArthur O'Dwyer   }
4907a0b0eeSArthur O'Dwyer   {
5007a0b0eeSArthur O'Dwyer     auto f = [](auto x) { return 10*x + 9; };
5107a0b0eeSArthur O'Dwyer     const MyBind bindexpr;
5207a0b0eeSArthur O'Dwyer     auto bound = std::bind(f, std::move(bindexpr));
5307a0b0eeSArthur O'Dwyer     assert(bound(7, 8) == 789);
5407a0b0eeSArthur O'Dwyer   }
5507a0b0eeSArthur O'Dwyer 
5607a0b0eeSArthur O'Dwyer   return 0;
5707a0b0eeSArthur O'Dwyer }
58