member_function.pass.cpp revision f5256e16dfc425c1d466f6308d4026d529ce9e0b
1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. 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 18struct A 19{ 20 char test0() {return 'a';} 21 char test1(int) {return 'b';} 22 char test2(int, double) {return 'c';} 23}; 24 25template <class F> 26void 27test0(F f) 28{ 29 { 30 A a; 31 assert(f(a) == 'a'); 32 A* ap = &a; 33 assert(f(ap) == 'a'); 34 } 35} 36 37template <class F> 38void 39test1(F f) 40{ 41 { 42 A a; 43 assert(f(a, 1) == 'b'); 44 A* ap = &a; 45 assert(f(ap, 2) == 'b'); 46 } 47} 48 49template <class F> 50void 51test2(F f) 52{ 53 { 54 A a; 55 assert(f(a, 1, 2) == 'c'); 56 A* ap = &a; 57 assert(f(ap, 2, 3.5) == 'c'); 58 } 59} 60 61int main() 62{ 63 test0(std::mem_fn(&A::test0)); 64 test1(std::mem_fn(&A::test1)); 65 test2(std::mem_fn(&A::test2)); 66} 67