bind_cv_test.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*==============================================================================
  2. Copyright (c) 2004 Peter Dimov
  3. Copyright (c) 2005-2010 Joel de Guzman
  4. Copyright (c) 2010 Thomas Heller
  5. Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. ==============================================================================*/
  8. #include <boost/config.hpp>
  9. #if defined(BOOST_MSVC)
  10. #pragma warning(disable: 4786) // identifier truncated in debug info
  11. #pragma warning(disable: 4710) // function not inlined
  12. #pragma warning(disable: 4711) // function selected for automatic inline expansion
  13. #pragma warning(disable: 4514) // unreferenced inline removed
  14. #endif
  15. #include <boost/phoenix/core.hpp>
  16. #include <boost/phoenix/bind.hpp>
  17. #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
  18. #pragma warning(push, 3)
  19. #endif
  20. #include <iostream>
  21. #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
  22. #pragma warning(pop)
  23. #endif
  24. #include <boost/detail/lightweight_test.hpp>
  25. struct X
  26. {
  27. typedef int result_type;
  28. int operator()()
  29. {
  30. return 17041;
  31. }
  32. int operator()() const
  33. {
  34. return -17041;
  35. }
  36. int operator()(int x1)
  37. {
  38. return x1;
  39. }
  40. int operator()(int x1) const
  41. {
  42. return -x1;
  43. }
  44. int operator()(int x1, int x2)
  45. {
  46. return x1+x2;
  47. }
  48. int operator()(int x1, int x2) const
  49. {
  50. return -(x1+x2);
  51. }
  52. int operator()(int x1, int x2, int x3)
  53. {
  54. return x1+x2+x3;
  55. }
  56. int operator()(int x1, int x2, int x3) const
  57. {
  58. return -(x1+x2+x3);
  59. }
  60. int operator()(int x1, int x2, int x3, int x4)
  61. {
  62. return x1+x2+x3+x4;
  63. }
  64. int operator()(int x1, int x2, int x3, int x4) const
  65. {
  66. return -(x1+x2+x3+x4);
  67. }
  68. int operator()(int x1, int x2, int x3, int x4, int x5)
  69. {
  70. return x1+x2+x3+x4+x5;
  71. }
  72. int operator()(int x1, int x2, int x3, int x4, int x5) const
  73. {
  74. return -(x1+x2+x3+x4+x5);
  75. }
  76. int operator()(int x1, int x2, int x3, int x4, int x5, int x6)
  77. {
  78. return x1+x2+x3+x4+x5+x6;
  79. }
  80. int operator()(int x1, int x2, int x3, int x4, int x5, int x6) const
  81. {
  82. return -(x1+x2+x3+x4+x5+x6);
  83. }
  84. int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7)
  85. {
  86. return x1+x2+x3+x4+x5+x6+x7;
  87. }
  88. int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7) const
  89. {
  90. return -(x1+x2+x3+x4+x5+x6+x7);
  91. }
  92. int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8)
  93. {
  94. return x1+x2+x3+x4+x5+x6+x7+x8;
  95. }
  96. int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8) const
  97. {
  98. return -(x1+x2+x3+x4+x5+x6+x7+x8);
  99. }
  100. int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9)
  101. {
  102. return x1+x2+x3+x4+x5+x6+x7+x8+x9;
  103. }
  104. int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9) const
  105. {
  106. return -(x1+x2+x3+x4+x5+x6+x7+x8+x9);
  107. }
  108. };
  109. template<class F> void test(F f, int r)
  110. {
  111. F const & cf = f;
  112. BOOST_TEST( cf() == -r );
  113. BOOST_TEST( f() == r );
  114. }
  115. int main()
  116. {
  117. using boost::phoenix::bind;
  118. using boost::phoenix::ref;
  119. using boost::phoenix::cref;
  120. test( bind(X()), 17041);
  121. test( bind(X(), 1), 1);
  122. test( bind(X(), 1, 2), 1+2);
  123. test( bind(X(), 1, 2, 3), 1+2+3);
  124. test( bind(X(), 1, 2, 3, 4), 1+2+3+4);
  125. test( bind(X(), 1, 2, 3, 4, 5), 1+2+3+4+5);
  126. test( bind(X(), 1, 2, 3, 4, 5, 6), 1+2+3+4+5+6);
  127. test( bind(X(), 1, 2, 3, 4, 5, 6, 7), 1+2+3+4+5+6+7);
  128. test( bind(X(), 1, 2, 3, 4, 5, 6, 7, 8), 1+2+3+4+5+6+7+8);
  129. test( bind(X(), 1, 2, 3, 4, 5, 6, 7, 8, 9), 1+2+3+4+5+6+7+8+9);
  130. return boost::report_errors();
  131. }