invoke_int_0.pass.cpp 969 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. // class function<R(ArgTypes...)>
  11. // R operator()(ArgTypes... args) const
  12. #include <functional>
  13. #include <cassert>
  14. // 0 args, return int
  15. int count = 0;
  16. int f_int_0()
  17. {
  18. return 3;
  19. }
  20. struct A_int_0
  21. {
  22. int operator()() {return 4;}
  23. };
  24. void
  25. test_int_0()
  26. {
  27. // function
  28. {
  29. std::function<int ()> r1(f_int_0);
  30. assert(r1() == 3);
  31. }
  32. // function pointer
  33. {
  34. int (*fp)() = f_int_0;
  35. std::function<int ()> r1(fp);
  36. assert(r1() == 3);
  37. }
  38. // functor
  39. {
  40. A_int_0 a0;
  41. std::function<int ()> r1(a0);
  42. assert(r1() == 4);
  43. }
  44. }
  45. int main()
  46. {
  47. test_int_0();
  48. }