invoke_void_0.pass.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. // UNSUPPORTED: c++98, c++03
  10. // <functional>
  11. // template<CopyConstructible Fn, CopyConstructible... Types>
  12. // unspecified bind(Fn, Types...);
  13. // template<Returnable R, CopyConstructible Fn, CopyConstructible... Types>
  14. // unspecified bind(Fn, Types...);
  15. #include <functional>
  16. #include <cassert>
  17. int count = 0;
  18. template <class F>
  19. void
  20. test(F f)
  21. {
  22. int save_count = count;
  23. f();
  24. assert(count == save_count + 1);
  25. }
  26. template <class F>
  27. void
  28. test_const(const F& f)
  29. {
  30. int save_count = count;
  31. f();
  32. assert(count == save_count + 2);
  33. }
  34. void f() {++count;}
  35. int g() {++count; return 0;}
  36. struct A_void_0
  37. {
  38. void operator()() {++count;}
  39. void operator()() const {count += 2;}
  40. };
  41. struct A_int_0
  42. {
  43. int operator()() {++count; return 4;}
  44. int operator()() const {count += 2; return 5;}
  45. };
  46. int main()
  47. {
  48. test(std::bind(f));
  49. test(std::bind(&f));
  50. test(std::bind(A_void_0()));
  51. test_const(std::bind(A_void_0()));
  52. test(std::bind<void>(f));
  53. test(std::bind<void>(&f));
  54. test(std::bind<void>(A_void_0()));
  55. test_const(std::bind<void>(A_void_0()));
  56. test(std::bind<void>(g));
  57. test(std::bind<void>(&g));
  58. test(std::bind<void>(A_int_0()));
  59. test_const(std::bind<void>(A_int_0()));
  60. }