invoke_no_variadics.pass.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. // class function<R()>
  11. // Test that we properly return both values and void for all non-variadic
  12. // overloads of function::operator()(...)
  13. #define _LIBCPP_HAS_NO_VARIADICS
  14. #include <functional>
  15. #include <cassert>
  16. int foo0() { return 42; }
  17. int foo1(int) { return 42; }
  18. int foo2(int, int) { return 42; }
  19. int foo3(int, int, int) { return 42; }
  20. int main()
  21. {
  22. {
  23. std::function<int()> f(&foo0);
  24. assert(f() == 42);
  25. }
  26. {
  27. std::function<int(int)> f(&foo1);
  28. assert(f(1) == 42);
  29. }
  30. {
  31. std::function<int(int, int)> f(&foo2);
  32. assert(f(1, 1) == 42);
  33. }
  34. {
  35. std::function<int(int, int, int)> f(&foo3);
  36. assert(f(1, 1, 1) == 42);
  37. }
  38. {
  39. std::function<void()> f(&foo0);
  40. f();
  41. }
  42. {
  43. std::function<void(int)> f(&foo1);
  44. f(1);
  45. }
  46. {
  47. std::function<void(int, int)> f(&foo2);
  48. f(1, 1);
  49. }
  50. {
  51. std::function<void(int, int, int)> f(&foo3);
  52. f(1, 1, 1);
  53. }
  54. }