bind_nested_rv_test.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #include <boost/config.hpp>
  2. //
  3. // bind_nested_rv_test.cpp
  4. //
  5. // Copyright (c) 2016 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/make_shared.hpp>
  13. #include <boost/function.hpp>
  14. #include <boost/detail/lightweight_test.hpp>
  15. //
  16. bool f1( boost::shared_ptr<int> p1 )
  17. {
  18. BOOST_TEST( p1 != 0 && *p1 == 1 );
  19. return true;
  20. }
  21. bool f2( boost::shared_ptr<int> p1, boost::shared_ptr<int> p2 )
  22. {
  23. BOOST_TEST( p1 != 0 && *p1 == 1 );
  24. BOOST_TEST( p2 != 0 && *p2 == 2 );
  25. return true;
  26. }
  27. bool f3( boost::shared_ptr<int> p1, boost::shared_ptr<int> p2, boost::shared_ptr<int> p3 )
  28. {
  29. BOOST_TEST( p1 != 0 && *p1 == 1 );
  30. BOOST_TEST( p2 != 0 && *p2 == 2 );
  31. BOOST_TEST( p3 != 0 && *p3 == 3 );
  32. return true;
  33. }
  34. bool f4( boost::shared_ptr<int> p1, boost::shared_ptr<int> p2, boost::shared_ptr<int> p3, boost::shared_ptr<int> p4 )
  35. {
  36. BOOST_TEST( p1 != 0 && *p1 == 1 );
  37. BOOST_TEST( p2 != 0 && *p2 == 2 );
  38. BOOST_TEST( p3 != 0 && *p3 == 3 );
  39. BOOST_TEST( p4 != 0 && *p4 == 4 );
  40. return true;
  41. }
  42. bool f5( boost::shared_ptr<int> p1, boost::shared_ptr<int> p2, boost::shared_ptr<int> p3, boost::shared_ptr<int> p4, boost::shared_ptr<int> p5 )
  43. {
  44. BOOST_TEST( p1 != 0 && *p1 == 1 );
  45. BOOST_TEST( p2 != 0 && *p2 == 2 );
  46. BOOST_TEST( p3 != 0 && *p3 == 3 );
  47. BOOST_TEST( p4 != 0 && *p4 == 4 );
  48. BOOST_TEST( p5 != 0 && *p5 == 5 );
  49. return true;
  50. }
  51. bool f6( boost::shared_ptr<int> p1, boost::shared_ptr<int> p2, boost::shared_ptr<int> p3, boost::shared_ptr<int> p4, boost::shared_ptr<int> p5, boost::shared_ptr<int> p6 )
  52. {
  53. BOOST_TEST( p1 != 0 && *p1 == 1 );
  54. BOOST_TEST( p2 != 0 && *p2 == 2 );
  55. BOOST_TEST( p3 != 0 && *p3 == 3 );
  56. BOOST_TEST( p4 != 0 && *p4 == 4 );
  57. BOOST_TEST( p5 != 0 && *p5 == 5 );
  58. BOOST_TEST( p6 != 0 && *p6 == 6 );
  59. return true;
  60. }
  61. bool f7( boost::shared_ptr<int> p1, boost::shared_ptr<int> p2, boost::shared_ptr<int> p3, boost::shared_ptr<int> p4, boost::shared_ptr<int> p5, boost::shared_ptr<int> p6, boost::shared_ptr<int> p7 )
  62. {
  63. BOOST_TEST( p1 != 0 && *p1 == 1 );
  64. BOOST_TEST( p2 != 0 && *p2 == 2 );
  65. BOOST_TEST( p3 != 0 && *p3 == 3 );
  66. BOOST_TEST( p4 != 0 && *p4 == 4 );
  67. BOOST_TEST( p5 != 0 && *p5 == 5 );
  68. BOOST_TEST( p6 != 0 && *p6 == 6 );
  69. BOOST_TEST( p7 != 0 && *p7 == 7 );
  70. return true;
  71. }
  72. bool f8( boost::shared_ptr<int> p1, boost::shared_ptr<int> p2, boost::shared_ptr<int> p3, boost::shared_ptr<int> p4, boost::shared_ptr<int> p5, boost::shared_ptr<int> p6, boost::shared_ptr<int> p7, boost::shared_ptr<int> p8 )
  73. {
  74. BOOST_TEST( p1 != 0 && *p1 == 1 );
  75. BOOST_TEST( p2 != 0 && *p2 == 2 );
  76. BOOST_TEST( p3 != 0 && *p3 == 3 );
  77. BOOST_TEST( p4 != 0 && *p4 == 4 );
  78. BOOST_TEST( p5 != 0 && *p5 == 5 );
  79. BOOST_TEST( p6 != 0 && *p6 == 6 );
  80. BOOST_TEST( p7 != 0 && *p7 == 7 );
  81. BOOST_TEST( p8 != 0 && *p8 == 8 );
  82. return true;
  83. }
  84. bool f9( boost::shared_ptr<int> p1, boost::shared_ptr<int> p2, boost::shared_ptr<int> p3, boost::shared_ptr<int> p4, boost::shared_ptr<int> p5, boost::shared_ptr<int> p6, boost::shared_ptr<int> p7, boost::shared_ptr<int> p8, boost::shared_ptr<int> p9 )
  85. {
  86. BOOST_TEST( p1 != 0 && *p1 == 1 );
  87. BOOST_TEST( p2 != 0 && *p2 == 2 );
  88. BOOST_TEST( p3 != 0 && *p3 == 3 );
  89. BOOST_TEST( p4 != 0 && *p4 == 4 );
  90. BOOST_TEST( p5 != 0 && *p5 == 5 );
  91. BOOST_TEST( p6 != 0 && *p6 == 6 );
  92. BOOST_TEST( p7 != 0 && *p7 == 7 );
  93. BOOST_TEST( p8 != 0 && *p8 == 8 );
  94. BOOST_TEST( p9 != 0 && *p9 == 9 );
  95. return true;
  96. }
  97. void test()
  98. {
  99. {
  100. boost::function<bool(boost::shared_ptr<int>)> f( f1 );
  101. ( boost::bind( f, _1 ) && boost::bind( f1, _1 ) )( boost::make_shared<int>( 1 ) );
  102. }
  103. {
  104. boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f2 );
  105. ( boost::bind( f, _1, _2 ) && boost::bind( f2, _1, _2 ) )( boost::make_shared<int>( 1 ), boost::make_shared<int>( 2 ) );
  106. }
  107. {
  108. boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f3 );
  109. ( boost::bind( f, _1, _2, _3 ) && boost::bind( f3, _1, _2, _3 ) )( boost::make_shared<int>( 1 ), boost::make_shared<int>( 2 ), boost::make_shared<int>( 3 ) );
  110. }
  111. {
  112. boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f3 );
  113. ( boost::bind( f, _1, _2, _3 ) && boost::bind( f3, _1, _2, _3 ) )( boost::make_shared<int>( 1 ), boost::make_shared<int>( 2 ), boost::make_shared<int>( 3 ) );
  114. }
  115. {
  116. boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f4 );
  117. ( boost::bind( f, _1, _2, _3, _4 ) && boost::bind( f4, _1, _2, _3, _4 ) )( boost::make_shared<int>( 1 ), boost::make_shared<int>( 2 ), boost::make_shared<int>( 3 ), boost::make_shared<int>( 4 ) );
  118. }
  119. {
  120. boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f5 );
  121. ( boost::bind( f, _1, _2, _3, _4, _5 ) && boost::bind( f5, _1, _2, _3, _4, _5 ) )( boost::make_shared<int>( 1 ), boost::make_shared<int>( 2 ), boost::make_shared<int>( 3 ), boost::make_shared<int>( 4 ), boost::make_shared<int>( 5 ) );
  122. }
  123. {
  124. boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f6 );
  125. ( boost::bind( f, _1, _2, _3, _4, _5, _6 ) && boost::bind( f6, _1, _2, _3, _4, _5, _6 ) )( boost::make_shared<int>( 1 ), boost::make_shared<int>( 2 ), boost::make_shared<int>( 3 ), boost::make_shared<int>( 4 ), boost::make_shared<int>( 5 ), boost::make_shared<int>( 6 ) );
  126. }
  127. {
  128. boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f7 );
  129. ( boost::bind( f, _1, _2, _3, _4, _5, _6, _7 ) && boost::bind( f7, _1, _2, _3, _4, _5, _6, _7 ) )( boost::make_shared<int>( 1 ), boost::make_shared<int>( 2 ), boost::make_shared<int>( 3 ), boost::make_shared<int>( 4 ), boost::make_shared<int>( 5 ), boost::make_shared<int>( 6 ), boost::make_shared<int>( 7 ) );
  130. }
  131. {
  132. boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f8 );
  133. ( boost::bind( f, _1, _2, _3, _4, _5, _6, _7, _8 ) && boost::bind( f8, _1, _2, _3, _4, _5, _6, _7, _8 ) )( boost::make_shared<int>( 1 ), boost::make_shared<int>( 2 ), boost::make_shared<int>( 3 ), boost::make_shared<int>( 4 ), boost::make_shared<int>( 5 ), boost::make_shared<int>( 6 ), boost::make_shared<int>( 7 ), boost::make_shared<int>( 8 ) );
  134. }
  135. {
  136. boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f9 );
  137. ( boost::bind( f, _1, _2, _3, _4, _5, _6, _7, _8, _9 ) && boost::bind( f9, _1, _2, _3, _4, _5, _6, _7, _8, _9 ) )( boost::make_shared<int>( 1 ), boost::make_shared<int>( 2 ), boost::make_shared<int>( 3 ), boost::make_shared<int>( 4 ), boost::make_shared<int>( 5 ), boost::make_shared<int>( 6 ), boost::make_shared<int>( 7 ), boost::make_shared<int>( 8 ), boost::make_shared<int>( 9 ) );
  138. }
  139. }
  140. int main()
  141. {
  142. test();
  143. return boost::report_errors();
  144. }