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...) const);
13 
14 #include <functional>
15 #include <cassert>
16 
17 struct A
18 {
19     char test0() const {return 'a';}
20     char test1(int) const {return 'b';}
21     char test2(int, double) const {return 'c';}
22 };
23 
24 template <class F>
25 void
26 test0(F f)
27 {
28     {
29     A a;
30     assert(f(a) == 'a');
31     A* ap = &a;
32     assert(f(ap) == 'a');
33     const A* cap = &a;
34     assert(f(cap) == 'a');
35     const F& cf = f;
36     assert(cf(ap) == 'a');
37     }
38 }
39 
40 template <class F>
41 void
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 A* cap = &a;
50     assert(f(cap, 2) == 'b');
51     const F& cf = f;
52     assert(cf(ap, 2) == 'b');
53     }
54 }
55 
56 template <class F>
57 void
58 test2(F f)
59 {
60     {
61     A a;
62     assert(f(a, 1, 2) == 'c');
63     A* ap = &a;
64     assert(f(ap, 2, 3.5) == 'c');
65     const A* cap = &a;
66     assert(f(cap, 2, 3.5) == 'c');
67     const F& cf = f;
68     assert(cf(ap, 2, 3.5) == 'c');
69     }
70 }
71 
72 int main(int, char**)
73 {
74     test0(std::mem_fn(&A::test0));
75     test1(std::mem_fn(&A::test1));
76     test2(std::mem_fn(&A::test2));
77 
78   return 0;
79 }
80