bind_fn2_test.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #include <boost/config.hpp>
  2. #if defined(BOOST_MSVC)
  3. #pragma warning(disable: 4786) // identifier truncated in debug info
  4. #pragma warning(disable: 4710) // function not inlined
  5. #pragma warning(disable: 4711) // function selected for automatic inline expansion
  6. #pragma warning(disable: 4514) // unreferenced inline removed
  7. #endif
  8. //
  9. // bind_fn2_test.cpp - test for functions w/ the type<> syntax
  10. //
  11. // Copyright (c) 2005, 2008 Peter Dimov
  12. //
  13. // Distributed under the Boost Software License, Version 1.0. (See
  14. // accompanying file LICENSE_1_0.txt or copy at
  15. // http://www.boost.org/LICENSE_1_0.txt)
  16. //
  17. #include <boost/bind.hpp>
  18. #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
  19. #pragma warning(push, 3)
  20. #endif
  21. #include <iostream>
  22. #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
  23. #pragma warning(pop)
  24. #endif
  25. #include <boost/detail/lightweight_test.hpp>
  26. long global_result;
  27. // long
  28. long f_0()
  29. {
  30. return global_result = 17041L;
  31. }
  32. long f_1(long a)
  33. {
  34. return global_result = a;
  35. }
  36. long f_2(long a, long b)
  37. {
  38. return global_result = a + 10 * b;
  39. }
  40. long f_3(long a, long b, long c)
  41. {
  42. return global_result = a + 10 * b + 100 * c;
  43. }
  44. long f_4(long a, long b, long c, long d)
  45. {
  46. return global_result = a + 10 * b + 100 * c + 1000 * d;
  47. }
  48. long f_5(long a, long b, long c, long d, long e)
  49. {
  50. return global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e;
  51. }
  52. long f_6(long a, long b, long c, long d, long e, long f)
  53. {
  54. return global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f;
  55. }
  56. long f_7(long a, long b, long c, long d, long e, long f, long g)
  57. {
  58. return global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g;
  59. }
  60. long f_8(long a, long b, long c, long d, long e, long f, long g, long h)
  61. {
  62. return global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h;
  63. }
  64. long f_9(long a, long b, long c, long d, long e, long f, long g, long h, long i)
  65. {
  66. return global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
  67. }
  68. // void
  69. void fv_0()
  70. {
  71. global_result = 17041L;
  72. }
  73. void fv_1(long a)
  74. {
  75. global_result = a;
  76. }
  77. void fv_2(long a, long b)
  78. {
  79. global_result = a + 10 * b;
  80. }
  81. void fv_3(long a, long b, long c)
  82. {
  83. global_result = a + 10 * b + 100 * c;
  84. }
  85. void fv_4(long a, long b, long c, long d)
  86. {
  87. global_result = a + 10 * b + 100 * c + 1000 * d;
  88. }
  89. void fv_5(long a, long b, long c, long d, long e)
  90. {
  91. global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e;
  92. }
  93. void fv_6(long a, long b, long c, long d, long e, long f)
  94. {
  95. global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f;
  96. }
  97. void fv_7(long a, long b, long c, long d, long e, long f, long g)
  98. {
  99. global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g;
  100. }
  101. void fv_8(long a, long b, long c, long d, long e, long f, long g, long h)
  102. {
  103. global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h;
  104. }
  105. void fv_9(long a, long b, long c, long d, long e, long f, long g, long h, long i)
  106. {
  107. global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
  108. }
  109. void function_test()
  110. {
  111. using namespace boost;
  112. bind( type<void>(), f_0 )(); BOOST_TEST( global_result == 17041L );
  113. bind( type<void>(), f_1, 1 )(); BOOST_TEST( global_result == 1L );
  114. bind( type<void>(), f_2, 1, 2 )(); BOOST_TEST( global_result == 21L );
  115. bind( type<void>(), f_3, 1, 2, 3 )(); BOOST_TEST( global_result == 321L );
  116. bind( type<void>(), f_4, 1, 2, 3, 4 )(); BOOST_TEST( global_result == 4321L );
  117. bind( type<void>(), f_5, 1, 2, 3, 4, 5 )(); BOOST_TEST( global_result == 54321L );
  118. bind( type<void>(), f_6, 1, 2, 3, 4, 5, 6 )(); BOOST_TEST( global_result == 654321L );
  119. bind( type<void>(), f_7, 1, 2, 3, 4, 5, 6, 7 )(); BOOST_TEST( global_result == 7654321L );
  120. bind( type<void>(), f_8, 1, 2, 3, 4, 5, 6, 7, 8 )(); BOOST_TEST( global_result == 87654321L );
  121. bind( type<void>(), f_9, 1, 2, 3, 4, 5, 6, 7, 8, 9 )(); BOOST_TEST( global_result == 987654321L );
  122. bind( type<void>(), fv_0 )(); BOOST_TEST( global_result == 17041L );
  123. bind( type<void>(), fv_1, 1 )(); BOOST_TEST( global_result == 1L );
  124. bind( type<void>(), fv_2, 1, 2 )(); BOOST_TEST( global_result == 21L );
  125. bind( type<void>(), fv_3, 1, 2, 3 )(); BOOST_TEST( global_result == 321L );
  126. bind( type<void>(), fv_4, 1, 2, 3, 4 )(); BOOST_TEST( global_result == 4321L );
  127. bind( type<void>(), fv_5, 1, 2, 3, 4, 5 )(); BOOST_TEST( global_result == 54321L );
  128. bind( type<void>(), fv_6, 1, 2, 3, 4, 5, 6 )(); BOOST_TEST( global_result == 654321L );
  129. bind( type<void>(), fv_7, 1, 2, 3, 4, 5, 6, 7 )(); BOOST_TEST( global_result == 7654321L );
  130. bind( type<void>(), fv_8, 1, 2, 3, 4, 5, 6, 7, 8 )(); BOOST_TEST( global_result == 87654321L );
  131. bind( type<void>(), fv_9, 1, 2, 3, 4, 5, 6, 7, 8, 9 )(); BOOST_TEST( global_result == 987654321L );
  132. }
  133. int main()
  134. {
  135. function_test();
  136. return boost::report_errors();
  137. }