member_function_const_volatile.pass.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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...) const volatile);
  12. #include <functional>
  13. #include <cassert>
  14. struct A
  15. {
  16. char test0() const volatile {return 'a';}
  17. char test1(int) const volatile {return 'b';}
  18. char test2(int, double) const volatile {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. const volatile A* cap = &a;
  30. assert(f(cap) == 'a');
  31. }
  32. }
  33. template <class F>
  34. void
  35. test1(F f)
  36. {
  37. {
  38. A a;
  39. assert(f(a, 1) == 'b');
  40. A* ap = &a;
  41. assert(f(ap, 2) == 'b');
  42. const volatile A* cap = &a;
  43. assert(f(cap, 2) == 'b');
  44. }
  45. }
  46. template <class F>
  47. void
  48. test2(F f)
  49. {
  50. {
  51. A a;
  52. assert(f(a, 1, 2) == 'c');
  53. A* ap = &a;
  54. assert(f(ap, 2, 3.5) == 'c');
  55. const volatile A* cap = &a;
  56. assert(f(cap, 2, 3.5) == 'c');
  57. }
  58. }
  59. int main()
  60. {
  61. test0(std::mem_fn(&A::test0));
  62. test1(std::mem_fn(&A::test1));
  63. test2(std::mem_fn(&A::test2));
  64. }