member_function.pass.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. // <functional>
  10. // template<Returnable R, class T, CopyConstructible... Args>
  11. // unspecified mem_fn(R (T::* pm)(Args...));
  12. #include <functional>
  13. #include <cassert>
  14. struct A
  15. {
  16. char test0() {return 'a';}
  17. char test1(int) {return 'b';}
  18. char test2(int, double) {return 'c';}
  19. };
  20. template <class F>
  21. void
  22. test0(F f)
  23. {
  24. {
  25. A a;
  26. assert(f(a) == 'a');
  27. A* ap = &a;
  28. assert(f(ap) == 'a');
  29. }
  30. }
  31. template <class F>
  32. void
  33. test1(F f)
  34. {
  35. {
  36. A a;
  37. assert(f(a, 1) == 'b');
  38. A* ap = &a;
  39. assert(f(ap, 2) == 'b');
  40. }
  41. }
  42. template <class F>
  43. void
  44. test2(F f)
  45. {
  46. {
  47. A a;
  48. assert(f(a, 1, 2) == 'c');
  49. A* ap = &a;
  50. assert(f(ap, 2, 3.5) == 'c');
  51. }
  52. }
  53. int main()
  54. {
  55. test0(std::mem_fn(&A::test0));
  56. test1(std::mem_fn(&A::test1));
  57. test2(std::mem_fn(&A::test2));
  58. }