bind_const_test.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*==============================================================================
  2. Copyright (c) 2001-2004 Peter Dimov and Multi Media Ltd.
  3. Copyright (c) 2001 David Abrahams
  4. Copyright (c) 2005-2010 Joel de Guzman
  5. Copyright (c) 2010 Thomas Heller
  6. Distributed under the Boost Software License, Version 1.0. (See accompanying
  7. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  8. ==============================================================================*/
  9. #include <boost/config.hpp>
  10. #if defined(BOOST_MSVC)
  11. #pragma warning(disable: 4786) // identifier truncated in debug info
  12. #pragma warning(disable: 4710) // function not inlined
  13. #pragma warning(disable: 4711) // function selected for automatic inline expansion
  14. #pragma warning(disable: 4514) // unreferenced inline removed
  15. #endif
  16. #include <boost/phoenix/core.hpp>
  17. #include <boost/phoenix/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. //
  27. long f_0()
  28. {
  29. return 17041L;
  30. }
  31. long f_1(long a)
  32. {
  33. return a;
  34. }
  35. long f_2(long a, long b)
  36. {
  37. return a + 10 * b;
  38. }
  39. long f_3(long a, long b, long c)
  40. {
  41. return a + 10 * b + 100 * c;
  42. }
  43. long f_4(long a, long b, long c, long d)
  44. {
  45. return a + 10 * b + 100 * c + 1000 * d;
  46. }
  47. long f_5(long a, long b, long c, long d, long e)
  48. {
  49. return a + 10 * b + 100 * c + 1000 * d + 10000 * e;
  50. }
  51. long f_6(long a, long b, long c, long d, long e, long f)
  52. {
  53. return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f;
  54. }
  55. long f_7(long a, long b, long c, long d, long e, long f, long g)
  56. {
  57. return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g;
  58. }
  59. long f_8(long a, long b, long c, long d, long e, long f, long g, long h)
  60. {
  61. return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h;
  62. }
  63. long f_9(long a, long b, long c, long d, long e, long f, long g, long h, long i)
  64. {
  65. return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
  66. }
  67. long global_result;
  68. void fv_0()
  69. {
  70. global_result = 17041L;
  71. }
  72. void fv_1(long a)
  73. {
  74. global_result = a;
  75. }
  76. void fv_2(long a, long b)
  77. {
  78. global_result = a + 10 * b;
  79. }
  80. void fv_3(long a, long b, long c)
  81. {
  82. global_result = a + 10 * b + 100 * c;
  83. }
  84. void fv_4(long a, long b, long c, long d)
  85. {
  86. global_result = a + 10 * b + 100 * c + 1000 * d;
  87. }
  88. void fv_5(long a, long b, long c, long d, long e)
  89. {
  90. global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e;
  91. }
  92. void fv_6(long a, long b, long c, long d, long e, long f)
  93. {
  94. global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f;
  95. }
  96. void fv_7(long a, long b, long c, long d, long e, long f, long g)
  97. {
  98. global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g;
  99. }
  100. void fv_8(long a, long b, long c, long d, long e, long f, long g, long h)
  101. {
  102. global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h;
  103. }
  104. void fv_9(long a, long b, long c, long d, long e, long f, long g, long h, long i)
  105. {
  106. global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
  107. }
  108. template<class F, class A> long tester(F const & f, A const & a)
  109. {
  110. return f(a);
  111. }
  112. template<class F, class A> long testerv(F const & f, A const & a)
  113. {
  114. f(a);
  115. return global_result;
  116. }
  117. void function_test()
  118. {
  119. using boost::phoenix::bind;
  120. using boost::phoenix::placeholders::_1;
  121. int const i = 1;
  122. BOOST_TEST( tester( bind(f_0), i ) == 17041L );
  123. BOOST_TEST( tester( bind(f_1, _1), i ) == 1L );
  124. BOOST_TEST( tester( bind(f_2, _1, 2), i ) == 21L );
  125. BOOST_TEST( tester( bind(f_3, _1, 2, 3), i ) == 321L );
  126. BOOST_TEST( tester( bind(f_4, _1, 2, 3, 4), i ) == 4321L );
  127. BOOST_TEST( tester( bind(f_5, _1, 2, 3, 4, 5), i ) == 54321L );
  128. BOOST_TEST( tester( bind(f_6, _1, 2, 3, 4, 5, 6), i ) == 654321L );
  129. BOOST_TEST( tester( bind(f_7, _1, 2, 3, 4, 5, 6, 7), i ) == 7654321L );
  130. BOOST_TEST( tester( bind(f_8, _1, 2, 3, 4, 5, 6, 7, 8), i ) == 87654321L );
  131. BOOST_TEST( tester( bind(f_9, _1, 2, 3, 4, 5, 6, 7, 8, 9), i ) == 987654321L );
  132. BOOST_TEST( testerv( bind(fv_0), i ) == 17041L );
  133. BOOST_TEST( testerv( bind(fv_1, _1), i ) == 1L );
  134. BOOST_TEST( testerv( bind(fv_2, _1, 2), i ) == 21L );
  135. BOOST_TEST( testerv( bind(fv_3, _1, 2, 3), i ) == 321L );
  136. BOOST_TEST( testerv( bind(fv_4, _1, 2, 3, 4), i ) == 4321L );
  137. BOOST_TEST( testerv( bind(fv_5, _1, 2, 3, 4, 5), i ) == 54321L );
  138. BOOST_TEST( testerv( bind(fv_6, _1, 2, 3, 4, 5, 6), i ) == 654321L );
  139. BOOST_TEST( testerv( bind(fv_7, _1, 2, 3, 4, 5, 6, 7), i ) == 7654321L );
  140. BOOST_TEST( testerv( bind(fv_8, _1, 2, 3, 4, 5, 6, 7, 8), i ) == 87654321L );
  141. BOOST_TEST( testerv( bind(fv_9, _1, 2, 3, 4, 5, 6, 7, 8, 9), i ) == 987654321L );
  142. }
  143. int main()
  144. {
  145. function_test();
  146. return boost::report_errors();
  147. }