1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <functional> 11 12 // template<Returnable R, class T, CopyConstructible... Args> 13 // unspecified mem_fn(R (T::* pm)(Args...)); 14 15 #include <functional> 16 #include <cassert> 17 18 #include "test_macros.h" 19 20 struct A 21 { 22 char test0() {return 'a';} 23 char test1(int) {return 'b';} 24 char test2(int, double) {return 'c';} 25 }; 26 27 template <class F> 28 void 29 test0(F f) 30 { 31 { 32 A a; 33 assert(f(a) == 'a'); 34 A* ap = &a; 35 assert(f(ap) == 'a'); 36 const F& cf = f; 37 assert(cf(ap) == 'a'); 38 } 39 } 40 41 template <class F> 42 void 43 test1(F f) 44 { 45 { 46 A a; 47 assert(f(a, 1) == 'b'); 48 A* ap = &a; 49 assert(f(ap, 2) == 'b'); 50 const F& cf = f; 51 assert(cf(ap, 2) == 'b'); 52 } 53 } 54 55 template <class F> 56 void 57 test2(F f) 58 { 59 { 60 A a; 61 assert(f(a, 1, 2) == 'c'); 62 A* ap = &a; 63 assert(f(ap, 2, 3.5) == 'c'); 64 const F& cf = f; 65 assert(cf(ap, 2, 3.5) == 'c'); 66 } 67 } 68 69 int main() 70 { 71 test0(std::mem_fn(&A::test0)); 72 test1(std::mem_fn(&A::test1)); 73 test2(std::mem_fn(&A::test2)); 74 #if TEST_STD_VER >= 11 75 static_assert((noexcept(std::mem_fn(&A::test0))), ""); // LWG#2489 76 #endif 77 } 78