Howard Hinnant | 94b2dd0 | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 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 | |
| 18 | struct A |
| 19 | { |
| 20 | char test0() {return 'a';} |
| 21 | char test1(int) {return 'b';} |
| 22 | char test2(int, double) {return 'c';} |
| 23 | }; |
| 24 | |
| 25 | template <class F> |
| 26 | void |
| 27 | test0(F f) |
| 28 | { |
| 29 | { |
| 30 | A a; |
| 31 | assert(f(a) == 'a'); |
| 32 | A* ap = &a; |
| 33 | assert(f(ap) == 'a'); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | template <class F> |
| 38 | void |
| 39 | test1(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 | |
| 49 | template <class F> |
| 50 | void |
| 51 | test2(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 | |
| 61 | int main() |
| 62 | { |
| 63 | test0(std::mem_fn(&A::test0)); |
| 64 | test1(std::mem_fn(&A::test1)); |
| 65 | test2(std::mem_fn(&A::test2)); |
| 66 | } |