]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/utilities/function.objects/bind/func.bind/func.bind.bind/nested.pass.cpp
Vendor import of libc++ trunk r351319 (just before the release_80
[FreeBSD/FreeBSD.git] / test / std / utilities / function.objects / bind / func.bind / func.bind.bind / nested.pass.cpp
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // UNSUPPORTED: c++98, c++03
11
12 // <functional>
13
14 // template<CopyConstructible Fn, CopyConstructible... Types>
15 //   unspecified bind(Fn, Types...);
16 // template<Returnable R, CopyConstructible Fn, CopyConstructible... Types>
17 //   unspecified bind(Fn, Types...);
18
19 // https://bugs.llvm.org/show_bug.cgi?id=16343
20
21 #include <cmath>
22 #include <functional>
23 #include <cassert>
24
25 struct power
26 {
27   template <typename T>
28   T
29   operator()(T a, T b)
30   {
31     return static_cast<T>(std::pow(a, b));
32   }
33 };
34
35 struct plus_one
36 {
37   template <typename T>
38   T
39   operator()(T a)
40   {
41     return a + 1;
42   }
43 };
44
45 int main()
46 {
47     using std::placeholders::_1;
48
49     auto g = std::bind(power(), 2, _1);
50     assert(g(5) == 32);
51     assert(std::bind(plus_one(), g)(5) == 33);
52 }