invoke_void_0.pass.cpp 1.5 KB

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