| 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 | // <functional> |
| 10 | |
| 11 | // const_mem_fun1_t |
| 12 | |
| 13 | // REQUIRES: c++03 || c++11 || c++14 |
| 14 | // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS |
| 15 | |
| 16 | #include <functional> |
| 17 | #include <type_traits> |
| 18 | #include <cassert> |
| 19 | |
| 20 | #include "test_macros.h" |
| 21 | |
| 22 | struct A |
| 23 | { |
| 24 | char a1() {return 5;} |
| 25 | short a2(int i) {return short(i+1);} |
| 26 | int a3() const {return 1;} |
| 27 | double a4(unsigned i) const {return i-1;} |
| 28 | }; |
| 29 | |
| 30 | int main(int, char**) |
| 31 | { |
| 32 | typedef std::const_mem_fun1_t<double, A, unsigned> F; |
| 33 | static_assert((std::is_base_of<std::binary_function<const A*, unsigned, double>, F>::value), "" ); |
| 34 | const F f(&A::a4); |
| 35 | const A a = A(); |
| 36 | assert(f(&a, 6) == 5); |
| 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | |