bind_no_placeholders_test.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // bind_no_placeholders_test.cpp - test for BOOST_BIND_NO_PLACEHOLDERS
  3. //
  4. // Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
  5. // Copyright (c) 2001 David Abrahams
  6. // Copyright (c) 2015 Peter Dimov
  7. //
  8. // Distributed under the Boost Software License, Version 1.0.
  9. // See accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt
  11. //
  12. #define BOOST_BIND_NO_PLACEHOLDERS
  13. #include <boost/bind.hpp>
  14. #include <boost/core/lightweight_test.hpp>
  15. //
  16. long f_0()
  17. {
  18. return 17041L;
  19. }
  20. long f_1(long a)
  21. {
  22. return a;
  23. }
  24. long f_2(long a, long b)
  25. {
  26. return a + 10 * b;
  27. }
  28. long f_3(long a, long b, long c)
  29. {
  30. return a + 10 * b + 100 * c;
  31. }
  32. long f_4(long a, long b, long c, long d)
  33. {
  34. return a + 10 * b + 100 * c + 1000 * d;
  35. }
  36. long f_5(long a, long b, long c, long d, long e)
  37. {
  38. return a + 10 * b + 100 * c + 1000 * d + 10000 * e;
  39. }
  40. long f_6(long a, long b, long c, long d, long e, long f)
  41. {
  42. return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f;
  43. }
  44. long f_7(long a, long b, long c, long d, long e, long f, long g)
  45. {
  46. return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g;
  47. }
  48. long f_8(long a, long b, long c, long d, long e, long f, long g, long h)
  49. {
  50. return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h;
  51. }
  52. long f_9(long a, long b, long c, long d, long e, long f, long g, long h, long i)
  53. {
  54. return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
  55. }
  56. void function_test()
  57. {
  58. using namespace boost;
  59. arg<1> _1;
  60. arg<2> _2;
  61. arg<3> _3;
  62. arg<4> _4;
  63. arg<5> _5;
  64. arg<6> _6;
  65. arg<7> _7;
  66. arg<8> _8;
  67. arg<9> _9;
  68. BOOST_TEST( bind(f_0)() == 17041L );
  69. BOOST_TEST( bind(f_1, _1)(1) == 1L );
  70. BOOST_TEST( bind(f_2, _1, _2)(1, 2) == 21L );
  71. BOOST_TEST( bind(f_3, _1, _2, _3)(1, 2, 3) == 321L );
  72. BOOST_TEST( bind(f_4, _1, _2, _3, _4)(1, 2, 3, 4) == 4321L );
  73. BOOST_TEST( bind(f_5, _1, _2, _3, _4, _5)(1, 2, 3, 4, 5) == 54321L );
  74. BOOST_TEST( bind(f_6, _1, _2, _3, _4, _5, _6)(1, 2, 3, 4, 5, 6) == 654321L );
  75. BOOST_TEST( bind(f_7, _1, _2, _3, _4, _5, _6, _7)(1, 2, 3, 4, 5, 6, 7) == 7654321L );
  76. BOOST_TEST( bind(f_8, _1, _2, _3, _4, _5, _6, _7, _8)(1, 2, 3, 4, 5, 6, 7, 8) == 87654321L );
  77. BOOST_TEST( bind(f_9, _1, _2, _3, _4, _5, _6, _7, _8, _9)(1, 2, 3, 4, 5, 6, 7, 8, 9) == 987654321L );
  78. }
  79. int main()
  80. {
  81. function_test();
  82. return boost::report_errors();
  83. }