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 // template<Returnable R, class T, CopyConstructible... Args>
12 // unspecified mem_fn(R (T::* pm)(Args...));
13
14 #include <functional>
15 #include <cassert>
16
17 #include "test_macros.h"
18
19 struct A
20 {
test0A21 char test0() {return 'a';}
test1A22 char test1(int) {return 'b';}
test2A23 char test2(int, double) {return 'c';}
24 };
25
26 template <class F>
27 void
test0(F f)28 test0(F f)
29 {
30 {
31 A a;
32 assert(f(a) == 'a');
33 A* ap = &a;
34 assert(f(ap) == 'a');
35 const F& cf = f;
36 assert(cf(ap) == 'a');
37 }
38 }
39
40 template <class F>
41 void
test1(F f)42 test1(F f)
43 {
44 {
45 A a;
46 assert(f(a, 1) == 'b');
47 A* ap = &a;
48 assert(f(ap, 2) == 'b');
49 const F& cf = f;
50 assert(cf(ap, 2) == 'b');
51 }
52 }
53
54 template <class F>
55 void
test2(F f)56 test2(F f)
57 {
58 {
59 A a;
60 assert(f(a, 1, 2) == 'c');
61 A* ap = &a;
62 assert(f(ap, 2, 3.5) == 'c');
63 const F& cf = f;
64 assert(cf(ap, 2, 3.5) == 'c');
65 }
66 }
67
main(int,char **)68 int main(int, char**)
69 {
70 test0(std::mem_fn(&A::test0));
71 test1(std::mem_fn(&A::test1));
72 test2(std::mem_fn(&A::test2));
73 #if TEST_STD_VER >= 11
74 static_assert((noexcept(std::mem_fn(&A::test0))), ""); // LWG#2489
75 #endif
76
77 return 0;
78 }
79