bind_function2_test.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #include <boost/config.hpp>
  2. //
  3. // bind_function2_test.cpp - regression test
  4. //
  5. // Copyright (c) 2015 Peter Dimov
  6. //
  7. // Distributed under the Boost Software License, Version 1.0.
  8. // See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt
  10. //
  11. #include <boost/bind.hpp>
  12. #include <boost/function.hpp>
  13. #include <boost/detail/lightweight_test.hpp>
  14. //
  15. void fv1( int & a )
  16. {
  17. a = 17041;
  18. }
  19. void fv2( int & a, int b )
  20. {
  21. a = b;
  22. }
  23. void fv3( int & a, int b, int c )
  24. {
  25. a = b + c;
  26. }
  27. void fv4( int & a, int b, int c, int d )
  28. {
  29. a = b + c + d;
  30. }
  31. void fv5( int & a, int b, int c, int d, int e )
  32. {
  33. a = b + c + d + e;
  34. }
  35. void fv6( int & a, int b, int c, int d, int e, int f )
  36. {
  37. a = b + c + d + e + f;
  38. }
  39. void fv7( int & a, int b, int c, int d, int e, int f, int g )
  40. {
  41. a = b + c + d + e + f + g;
  42. }
  43. void fv8( int & a, int b, int c, int d, int e, int f, int g, int h )
  44. {
  45. a = b + c + d + e + f + g + h;
  46. }
  47. void fv9( int & a, int b, int c, int d, int e, int f, int g, int h, int i )
  48. {
  49. a = b + c + d + e + f + g + h + i;
  50. }
  51. void function_test()
  52. {
  53. int x = 0;
  54. {
  55. boost::function<void(int&)> fw1 = boost::bind( fv1, _1 );
  56. fw1( x ); BOOST_TEST( x == 17041 );
  57. }
  58. {
  59. boost::function<void(int&, int)> fw2 = boost::bind( fv2, _1, _2 );
  60. fw2( x, 1 ); BOOST_TEST( x == 1 );
  61. }
  62. {
  63. boost::function<void(int&, int, int)> fw3 = boost::bind( fv3, _1, _2, _3 );
  64. fw3( x, 1, 2 ); BOOST_TEST( x == 1+2 );
  65. }
  66. {
  67. boost::function<void(int&, int, int, int)> fw4 = boost::bind( fv4, _1, _2, _3, _4 );
  68. fw4( x, 1, 2, 3 ); BOOST_TEST( x == 1+2+3 );
  69. }
  70. {
  71. boost::function<void(int&, int, int, int, int)> fw5 = boost::bind( fv5, _1, _2, _3, _4, _5 );
  72. fw5( x, 1, 2, 3, 4 ); BOOST_TEST( x == 1+2+3+4 );
  73. }
  74. {
  75. boost::function<void(int&, int, int, int, int, int)> fw6 = boost::bind( fv6, _1, _2, _3, _4, _5, _6 );
  76. fw6( x, 1, 2, 3, 4, 5 ); BOOST_TEST( x == 1+2+3+4+5 );
  77. }
  78. {
  79. boost::function<void(int&, int, int, int, int, int, int)> fw7 = boost::bind( fv7, _1, _2, _3, _4, _5, _6, _7 );
  80. fw7( x, 1, 2, 3, 4, 5, 6 ); BOOST_TEST( x == 1+2+3+4+5+6 );
  81. }
  82. {
  83. boost::function<void(int&, int, int, int, int, int, int, int)> fw8 = boost::bind( fv8, _1, _2, _3, _4, _5, _6, _7, _8 );
  84. fw8( x, 1, 2, 3, 4, 5, 6, 7 ); BOOST_TEST( x == 1+2+3+4+5+6+7 );
  85. }
  86. {
  87. boost::function<void(int&, int, int, int, int, int, int, int, int)> fw9 = boost::bind( fv9, _1, _2, _3, _4, _5, _6, _7, _8, _9 );
  88. fw9( x, 1, 2, 3, 4, 5, 6, 7, 8 ); BOOST_TEST( x == 1+2+3+4+5+6+7+8 );
  89. }
  90. }
  91. int main()
  92. {
  93. function_test();
  94. return boost::report_errors();
  95. }