bind_function_ap_test.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. #include <boost/config.hpp>
  2. //
  3. // bind_function_ap_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. #if defined( BOOST_NO_AUTO_PTR )
  12. int main()
  13. {
  14. }
  15. #else
  16. #if defined( __GNUC__ ) && ( __GNUC__ * 100 + __GNUC_MINOR__ >= 406 )
  17. # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
  18. #elif defined( __clang__ ) && defined( __has_warning )
  19. # if __has_warning( "-Wdeprecated-declarations" )
  20. # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
  21. # endif
  22. #endif
  23. #include <boost/bind.hpp>
  24. #include <boost/function.hpp>
  25. #include <boost/detail/lightweight_test.hpp>
  26. #include <memory>
  27. //
  28. void fv1( std::auto_ptr<int> p1 )
  29. {
  30. BOOST_TEST( *p1 == 1 );
  31. }
  32. void fv2( std::auto_ptr<int> p1, std::auto_ptr<int> p2 )
  33. {
  34. BOOST_TEST( *p1 == 1 );
  35. BOOST_TEST( *p2 == 2 );
  36. }
  37. void fv3( std::auto_ptr<int> p1, std::auto_ptr<int> p2, std::auto_ptr<int> p3 )
  38. {
  39. BOOST_TEST( *p1 == 1 );
  40. BOOST_TEST( *p2 == 2 );
  41. BOOST_TEST( *p3 == 3 );
  42. }
  43. void fv4( std::auto_ptr<int> p1, std::auto_ptr<int> p2, std::auto_ptr<int> p3, std::auto_ptr<int> p4 )
  44. {
  45. BOOST_TEST( *p1 == 1 );
  46. BOOST_TEST( *p2 == 2 );
  47. BOOST_TEST( *p3 == 3 );
  48. BOOST_TEST( *p4 == 4 );
  49. }
  50. void fv5( std::auto_ptr<int> p1, std::auto_ptr<int> p2, std::auto_ptr<int> p3, std::auto_ptr<int> p4, std::auto_ptr<int> p5 )
  51. {
  52. BOOST_TEST( *p1 == 1 );
  53. BOOST_TEST( *p2 == 2 );
  54. BOOST_TEST( *p3 == 3 );
  55. BOOST_TEST( *p4 == 4 );
  56. BOOST_TEST( *p5 == 5 );
  57. }
  58. void fv6( std::auto_ptr<int> p1, std::auto_ptr<int> p2, std::auto_ptr<int> p3, std::auto_ptr<int> p4, std::auto_ptr<int> p5, std::auto_ptr<int> p6 )
  59. {
  60. BOOST_TEST( *p1 == 1 );
  61. BOOST_TEST( *p2 == 2 );
  62. BOOST_TEST( *p3 == 3 );
  63. BOOST_TEST( *p4 == 4 );
  64. BOOST_TEST( *p5 == 5 );
  65. BOOST_TEST( *p6 == 6 );
  66. }
  67. void fv7( std::auto_ptr<int> p1, std::auto_ptr<int> p2, std::auto_ptr<int> p3, std::auto_ptr<int> p4, std::auto_ptr<int> p5, std::auto_ptr<int> p6, std::auto_ptr<int> p7 )
  68. {
  69. BOOST_TEST( *p1 == 1 );
  70. BOOST_TEST( *p2 == 2 );
  71. BOOST_TEST( *p3 == 3 );
  72. BOOST_TEST( *p4 == 4 );
  73. BOOST_TEST( *p5 == 5 );
  74. BOOST_TEST( *p6 == 6 );
  75. BOOST_TEST( *p7 == 7 );
  76. }
  77. void fv8( std::auto_ptr<int> p1, std::auto_ptr<int> p2, std::auto_ptr<int> p3, std::auto_ptr<int> p4, std::auto_ptr<int> p5, std::auto_ptr<int> p6, std::auto_ptr<int> p7, std::auto_ptr<int> p8 )
  78. {
  79. BOOST_TEST( *p1 == 1 );
  80. BOOST_TEST( *p2 == 2 );
  81. BOOST_TEST( *p3 == 3 );
  82. BOOST_TEST( *p4 == 4 );
  83. BOOST_TEST( *p5 == 5 );
  84. BOOST_TEST( *p6 == 6 );
  85. BOOST_TEST( *p7 == 7 );
  86. BOOST_TEST( *p8 == 8 );
  87. }
  88. void fv9( std::auto_ptr<int> p1, std::auto_ptr<int> p2, std::auto_ptr<int> p3, std::auto_ptr<int> p4, std::auto_ptr<int> p5, std::auto_ptr<int> p6, std::auto_ptr<int> p7, std::auto_ptr<int> p8, std::auto_ptr<int> p9 )
  89. {
  90. BOOST_TEST( *p1 == 1 );
  91. BOOST_TEST( *p2 == 2 );
  92. BOOST_TEST( *p3 == 3 );
  93. BOOST_TEST( *p4 == 4 );
  94. BOOST_TEST( *p5 == 5 );
  95. BOOST_TEST( *p6 == 6 );
  96. BOOST_TEST( *p7 == 7 );
  97. BOOST_TEST( *p8 == 8 );
  98. BOOST_TEST( *p9 == 9 );
  99. }
  100. void test()
  101. {
  102. {
  103. boost::function<void(std::auto_ptr<int>)> fw1 = boost::bind( fv1, _1 );
  104. std::auto_ptr<int> p1( new int(1) );
  105. fw1( p1 );
  106. }
  107. {
  108. boost::function<void(std::auto_ptr<int>, std::auto_ptr<int>)> fw2 = boost::bind( fv2, _1, _2 );
  109. std::auto_ptr<int> p1( new int(1) );
  110. std::auto_ptr<int> p2( new int(2) );
  111. fw2( p1, p2 );
  112. }
  113. {
  114. boost::function<void(std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>)> fw3 = boost::bind( fv3, _1, _2, _3 );
  115. std::auto_ptr<int> p1( new int(1) );
  116. std::auto_ptr<int> p2( new int(2) );
  117. std::auto_ptr<int> p3( new int(3) );
  118. fw3( p1, p2, p3 );
  119. }
  120. {
  121. boost::function<void(std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>)> fw4 = boost::bind( fv4, _1, _2, _3, _4 );
  122. std::auto_ptr<int> p1( new int(1) );
  123. std::auto_ptr<int> p2( new int(2) );
  124. std::auto_ptr<int> p3( new int(3) );
  125. std::auto_ptr<int> p4( new int(4) );
  126. fw4( p1, p2, p3, p4 );
  127. }
  128. {
  129. boost::function<void(std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>)> fw5 = boost::bind( fv5, _1, _2, _3, _4, _5 );
  130. std::auto_ptr<int> p1( new int(1) );
  131. std::auto_ptr<int> p2( new int(2) );
  132. std::auto_ptr<int> p3( new int(3) );
  133. std::auto_ptr<int> p4( new int(4) );
  134. std::auto_ptr<int> p5( new int(5) );
  135. fw5( p1, p2, p3, p4, p5 );
  136. }
  137. {
  138. boost::function<void(std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>)> fw6 = boost::bind( fv6, _1, _2, _3, _4, _5, _6 );
  139. std::auto_ptr<int> p1( new int(1) );
  140. std::auto_ptr<int> p2( new int(2) );
  141. std::auto_ptr<int> p3( new int(3) );
  142. std::auto_ptr<int> p4( new int(4) );
  143. std::auto_ptr<int> p5( new int(5) );
  144. std::auto_ptr<int> p6( new int(6) );
  145. fw6( p1, p2, p3, p4, p5, p6 );
  146. }
  147. {
  148. boost::function<void(std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>)> fw7 = boost::bind( fv7, _1, _2, _3, _4, _5, _6, _7 );
  149. std::auto_ptr<int> p1( new int(1) );
  150. std::auto_ptr<int> p2( new int(2) );
  151. std::auto_ptr<int> p3( new int(3) );
  152. std::auto_ptr<int> p4( new int(4) );
  153. std::auto_ptr<int> p5( new int(5) );
  154. std::auto_ptr<int> p6( new int(6) );
  155. std::auto_ptr<int> p7( new int(7) );
  156. fw7( p1, p2, p3, p4, p5, p6, p7 );
  157. }
  158. {
  159. boost::function<void(std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>)> fw8 = boost::bind( fv8, _1, _2, _3, _4, _5, _6, _7, _8 );
  160. std::auto_ptr<int> p1( new int(1) );
  161. std::auto_ptr<int> p2( new int(2) );
  162. std::auto_ptr<int> p3( new int(3) );
  163. std::auto_ptr<int> p4( new int(4) );
  164. std::auto_ptr<int> p5( new int(5) );
  165. std::auto_ptr<int> p6( new int(6) );
  166. std::auto_ptr<int> p7( new int(7) );
  167. std::auto_ptr<int> p8( new int(8) );
  168. fw8( p1, p2, p3, p4, p5, p6, p7, p8 );
  169. }
  170. {
  171. boost::function<void(std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>)> fw9 = boost::bind( fv9, _1, _2, _3, _4, _5, _6, _7, _8, _9 );
  172. std::auto_ptr<int> p1( new int(1) );
  173. std::auto_ptr<int> p2( new int(2) );
  174. std::auto_ptr<int> p3( new int(3) );
  175. std::auto_ptr<int> p4( new int(4) );
  176. std::auto_ptr<int> p5( new int(5) );
  177. std::auto_ptr<int> p6( new int(6) );
  178. std::auto_ptr<int> p7( new int(7) );
  179. std::auto_ptr<int> p8( new int(8) );
  180. std::auto_ptr<int> p9( new int(9) );
  181. fw9( p1, p2, p3, p4, p5, p6, p7, p8, p9 );
  182. }
  183. }
  184. int main()
  185. {
  186. test();
  187. return boost::report_errors();
  188. }
  189. #endif // #if defined( BOOST_NO_AUTO_PTR )