bind_noexcept_test.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // bind_noexcept_test.cpp
  3. //
  4. // Copyright 2017 Peter Dimov
  5. //
  6. // Distributed under the Boost Software License, Version 1.0.
  7. // See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #include <boost/bind.hpp>
  11. #include <boost/core/lightweight_test.hpp>
  12. #include <boost/config.hpp>
  13. #if defined(BOOST_NO_CXX11_NOEXCEPT)
  14. int main()
  15. {
  16. }
  17. #else
  18. //
  19. long f_0() noexcept
  20. {
  21. return 17041L;
  22. }
  23. long f_1(long a) noexcept
  24. {
  25. return a;
  26. }
  27. long f_2(long a, long b) noexcept
  28. {
  29. return a + 10 * b;
  30. }
  31. long f_3(long a, long b, long c) noexcept
  32. {
  33. return a + 10 * b + 100 * c;
  34. }
  35. long f_4(long a, long b, long c, long d) noexcept
  36. {
  37. return a + 10 * b + 100 * c + 1000 * d;
  38. }
  39. long f_5(long a, long b, long c, long d, long e) noexcept
  40. {
  41. return a + 10 * b + 100 * c + 1000 * d + 10000 * e;
  42. }
  43. long f_6(long a, long b, long c, long d, long e, long f) noexcept
  44. {
  45. return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f;
  46. }
  47. long f_7(long a, long b, long c, long d, long e, long f, long g) noexcept
  48. {
  49. return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g;
  50. }
  51. long f_8(long a, long b, long c, long d, long e, long f, long g, long h) noexcept
  52. {
  53. return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h;
  54. }
  55. long f_9(long a, long b, long c, long d, long e, long f, long g, long h, long i) noexcept
  56. {
  57. return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
  58. }
  59. void function_test()
  60. {
  61. int const i = 1;
  62. BOOST_TEST( boost::bind(f_0)(i) == 17041L );
  63. BOOST_TEST( boost::bind(f_1, _1)(i) == 1L );
  64. BOOST_TEST( boost::bind(f_2, _1, 2)(i) == 21L );
  65. BOOST_TEST( boost::bind(f_3, _1, 2, 3)(i) == 321L );
  66. BOOST_TEST( boost::bind(f_4, _1, 2, 3, 4)(i) == 4321L );
  67. BOOST_TEST( boost::bind(f_5, _1, 2, 3, 4, 5)(i) == 54321L );
  68. BOOST_TEST( boost::bind(f_6, _1, 2, 3, 4, 5, 6)(i) == 654321L );
  69. BOOST_TEST( boost::bind(f_7, _1, 2, 3, 4, 5, 6, 7)(i) == 7654321L );
  70. BOOST_TEST( boost::bind(f_8, _1, 2, 3, 4, 5, 6, 7, 8)(i) == 87654321L );
  71. BOOST_TEST( boost::bind(f_9, _1, 2, 3, 4, 5, 6, 7, 8, 9)(i) == 987654321L );
  72. }
  73. int main()
  74. {
  75. function_test();
  76. return boost::report_errors();
  77. }
  78. #endif