//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // In C++17, the function adapters mem_fun/mem_fun_ref, etc have been removed. // However, for backwards compatibility, if _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS // is defined before including , then they will be restored. // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS #include #include #include #include "test_macros.h" int identity(int v) { return v; } int sum(int a, int b) { return a + b; } struct Foo { int zero() { return 0; } int zero_const() const { return 1; } int identity(int v) const { return v; } int sum(int a, int b) const { return a + b; } }; int main(int, char**) { typedef std::pointer_to_unary_function PUF; typedef std::pointer_to_binary_function PBF; static_assert( (std::is_same(identity)))>::value), ""); static_assert( (std::is_same(sum)))>::value), ""); assert((std::ptr_fun(identity)(4) == 4)); assert((std::ptr_fun(sum)(4, 5) == 9)); Foo f; assert((std::mem_fn(&Foo::identity)(f, 5) == 5)); assert((std::mem_fn(&Foo::sum)(f, 5, 6) == 11)); typedef std::mem_fun_ref_t MFR; typedef std::const_mem_fun_ref_t CMFR; static_assert( (std::is_same::value), ""); static_assert((std::is_same::value), ""); assert((std::mem_fun_ref(&Foo::zero)(f) == 0)); assert((std::mem_fun_ref(&Foo::identity)(f, 5) == 5)); return 0; }