xref: /llvm-project/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/nested.pass.cpp (revision 57b08b0944046a6a57ee9b7b479181f548a5b9b4)
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++98, c++03
10 
11 // <functional>
12 
13 // template<CopyConstructible Fn, CopyConstructible... Types>
14 //   unspecified bind(Fn, Types...);
15 // template<Returnable R, CopyConstructible Fn, CopyConstructible... Types>
16 //   unspecified bind(Fn, Types...);
17 
18 // https://bugs.llvm.org/show_bug.cgi?id=16343
19 
20 #include <cmath>
21 #include <functional>
22 #include <cassert>
23 
24 struct power
25 {
26   template <typename T>
27   T
28   operator()(T a, T b)
29   {
30     return static_cast<T>(std::pow(a, b));
31   }
32 };
33 
34 struct plus_one
35 {
36   template <typename T>
37   T
38   operator()(T a)
39   {
40     return a + 1;
41   }
42 };
43 
44 int main()
45 {
46     using std::placeholders::_1;
47 
48     auto g = std::bind(power(), 2, _1);
49     assert(g(5) == 32);
50     assert(std::bind(plus_one(), g)(5) == 33);
51 }
52