bind_cv_test.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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_cv_test.cpp
  10. //
  11. // Copyright (c) 2004 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. struct X
  27. {
  28. // SGI-related compilers have odd compiler-synthesized ctors dtors
  29. #ifdef __PATHSCALE__
  30. X() {}
  31. ~X() {}
  32. #endif
  33. int operator()()
  34. {
  35. return 17041;
  36. }
  37. int operator()() const
  38. {
  39. return -17041;
  40. }
  41. int operator()(int x1)
  42. {
  43. return x1;
  44. }
  45. int operator()(int x1) const
  46. {
  47. return -x1;
  48. }
  49. int operator()(int x1, int x2)
  50. {
  51. return x1+x2;
  52. }
  53. int operator()(int x1, int x2) const
  54. {
  55. return -(x1+x2);
  56. }
  57. int operator()(int x1, int x2, int x3)
  58. {
  59. return x1+x2+x3;
  60. }
  61. int operator()(int x1, int x2, int x3) const
  62. {
  63. return -(x1+x2+x3);
  64. }
  65. int operator()(int x1, int x2, int x3, int x4)
  66. {
  67. return x1+x2+x3+x4;
  68. }
  69. int operator()(int x1, int x2, int x3, int x4) const
  70. {
  71. return -(x1+x2+x3+x4);
  72. }
  73. int operator()(int x1, int x2, int x3, int x4, int x5)
  74. {
  75. return x1+x2+x3+x4+x5;
  76. }
  77. int operator()(int x1, int x2, int x3, int x4, int x5) const
  78. {
  79. return -(x1+x2+x3+x4+x5);
  80. }
  81. int operator()(int x1, int x2, int x3, int x4, int x5, int x6)
  82. {
  83. return x1+x2+x3+x4+x5+x6;
  84. }
  85. int operator()(int x1, int x2, int x3, int x4, int x5, int x6) const
  86. {
  87. return -(x1+x2+x3+x4+x5+x6);
  88. }
  89. int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7)
  90. {
  91. return x1+x2+x3+x4+x5+x6+x7;
  92. }
  93. int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7) const
  94. {
  95. return -(x1+x2+x3+x4+x5+x6+x7);
  96. }
  97. int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8)
  98. {
  99. return x1+x2+x3+x4+x5+x6+x7+x8;
  100. }
  101. int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8) const
  102. {
  103. return -(x1+x2+x3+x4+x5+x6+x7+x8);
  104. }
  105. int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9)
  106. {
  107. return x1+x2+x3+x4+x5+x6+x7+x8+x9;
  108. }
  109. int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9) const
  110. {
  111. return -(x1+x2+x3+x4+x5+x6+x7+x8+x9);
  112. }
  113. };
  114. template<class F> void test(F f, int r)
  115. {
  116. F const & cf = f;
  117. BOOST_TEST( cf() == -r );
  118. BOOST_TEST( f() == r );
  119. }
  120. int main()
  121. {
  122. test( boost::bind<int>( X() ), 17041 );
  123. test( boost::bind<int>( X(), 1 ), 1 );
  124. test( boost::bind<int>( X(), 1, 2 ), 1+2 );
  125. test( boost::bind<int>( X(), 1, 2, 3 ), 1+2+3 );
  126. test( boost::bind<int>( X(), 1, 2, 3, 4 ), 1+2+3+4 );
  127. test( boost::bind<int>( X(), 1, 2, 3, 4, 5 ), 1+2+3+4+5 );
  128. test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6 ), 1+2+3+4+5+6 );
  129. test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6, 7 ), 1+2+3+4+5+6+7 );
  130. test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6, 7, 8 ), 1+2+3+4+5+6+7+8 );
  131. test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6, 7, 8, 9 ), 1+2+3+4+5+6+7+8+9 );
  132. return boost::report_errors();
  133. }