1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
17 #define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS
22 int identity(int v) { return v; }
23 int sum(int a, int b) { return a + b; }
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; }
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));
39 assert((std::mem_fn(&Foo::identity)(f, 5) == 5));
40 assert((std::mem_fn(&Foo::sum)(f, 5, 6) == 11));
42 typedef std::mem_fun_ref_t<int, Foo> MFR;
43 typedef std::const_mem_fun_ref_t<int, Foo> CMFR;
45 assert((std::mem_fun_ref(&Foo::zero)(f) == 0));
46 assert((std::mem_fun_ref(&Foo::identity)(f, 5) == 5));