bind_fwd2_test.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #include <boost/config.hpp>
  2. //
  3. // bind_fwd2_test.cpp - forwarding test for 2 arguments
  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/detail/lightweight_test.hpp>
  13. //
  14. int fv1( int const & a )
  15. {
  16. return a;
  17. }
  18. void fv2_1( int & a, int const & b )
  19. {
  20. a = b;
  21. }
  22. void fv2_2( int const & a, int & b )
  23. {
  24. b = a;
  25. }
  26. int fv2_3( int const & a, int const & b )
  27. {
  28. return a+b;
  29. }
  30. void test()
  31. {
  32. {
  33. int const a = 1;
  34. int r = boost::bind( fv1, _1 )( a );
  35. BOOST_TEST( r == 1 );
  36. }
  37. {
  38. int r = boost::bind( fv1, _1 )( 1 );
  39. BOOST_TEST( r == 1 );
  40. }
  41. {
  42. int a = 1;
  43. int const b = 2;
  44. boost::bind( fv2_1, _1, _2 )( a, b );
  45. BOOST_TEST( a == 2 );
  46. }
  47. {
  48. int a = 1;
  49. boost::bind( fv2_1, _1, _2 )( a, 2 );
  50. BOOST_TEST( a == 2 );
  51. }
  52. {
  53. int const a = 1;
  54. int b = 2;
  55. boost::bind( fv2_2, _1, _2 )( a, b );
  56. BOOST_TEST( b == 1 );
  57. }
  58. {
  59. int b = 2;
  60. boost::bind( fv2_2, _1, _2 )( 1, b );
  61. BOOST_TEST( b == 1 );
  62. }
  63. {
  64. int const a = 1;
  65. int const b = 2;
  66. int r = boost::bind( fv2_3, _1, _2 )( a, b );
  67. BOOST_TEST( r == 3 );
  68. }
  69. {
  70. int const a = 1;
  71. int r = boost::bind( fv2_3, _1, _2 )( a, 2 );
  72. BOOST_TEST( r == 3 );
  73. }
  74. {
  75. int const b = 2;
  76. int r = boost::bind( fv2_3, _1, _2 )( 1, b );
  77. BOOST_TEST( r == 3 );
  78. }
  79. {
  80. int r = boost::bind( fv2_3, _1, _2 )( 1, 2 );
  81. BOOST_TEST( r == 3 );
  82. }
  83. }
  84. int main()
  85. {
  86. test();
  87. return boost::report_errors();
  88. }