]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/libcxx/depr/depr.function.objects/depr.adaptors.cxx1z.pass.cpp
Vendor import of libc++ trunk r302418:
[FreeBSD/FreeBSD.git] / test / libcxx / depr / depr.function.objects / depr.adaptors.cxx1z.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 // <functional>
11
12
13 //  In C++17, the function adapters mem_fun/mem_fun_ref, etc have been removed.
14 //  However, for backwards compatibility, if _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS
15 //  is defined before including <functional>, then they will be restored.
16
17 #define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS
18
19 #include <functional>
20 #include <cassert>
21
22 int identity(int v) { return v; }
23 int sum(int a, int b) { return a + b; }
24
25 struct Foo {
26         int zero() const { return 0; }
27         int identity(int v) const { return v; }
28         int sum(int a, int b) const { return a + b; }
29 };
30
31 int main()
32 {
33         typedef std::pointer_to_unary_function<int, int> PUF;
34         typedef std::pointer_to_binary_function<int, int, int> PBF;
35         assert((std::ptr_fun<int, int>(identity)(4) == 4));
36         assert((std::ptr_fun<int, int, int>(sum)(4, 5) == 9));
37
38         Foo f;
39         assert((std::mem_fn(&Foo::identity)(f, 5) == 5));
40         assert((std::mem_fn(&Foo::sum)(f, 5, 6) == 11));
41
42     typedef std::mem_fun_ref_t<int, Foo> MFR;
43     typedef std::const_mem_fun_ref_t<int, Foo> CMFR;
44
45         assert((std::mem_fun_ref(&Foo::zero)(f) == 0));
46         assert((std::mem_fun_ref(&Foo::identity)(f, 5) == 5));
47 }