bind_fastcall_test.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*==============================================================================
  2. Copyright (c) 2002 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. #define BOOST_BIND_ENABLE_FASTCALL
  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 __fastcall f_0()
  28. {
  29. return 17041L;
  30. }
  31. long __fastcall f_1(long a)
  32. {
  33. return a;
  34. }
  35. long __fastcall f_2(long a, long b)
  36. {
  37. return a + 10 * b;
  38. }
  39. long __fastcall f_3(long a, long b, long c)
  40. {
  41. return a + 10 * b + 100 * c;
  42. }
  43. long __fastcall f_4(long a, long b, long c, long d)
  44. {
  45. return a + 10 * b + 100 * c + 1000 * d;
  46. }
  47. long __fastcall 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 __fastcall 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 __fastcall 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 __fastcall 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 __fastcall 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. void function_test()
  68. {
  69. using boost::phoenix::bind;
  70. int const i = 1;
  71. BOOST_TEST( bind(f_0)(i) == 17041L );
  72. BOOST_TEST( bind(f_1, _1)(i) == 1L );
  73. BOOST_TEST( bind(f_2, _1, 2)(i) == 21L );
  74. BOOST_TEST( bind(f_3, _1, 2, 3)(i) == 321L );
  75. BOOST_TEST( bind(f_4, _1, 2, 3, 4)(i) == 4321L );
  76. BOOST_TEST( bind(f_5, _1, 2, 3, 4, 5)(i) == 54321L );
  77. BOOST_TEST( bind(f_6, _1, 2, 3, 4, 5, 6)(i) == 654321L );
  78. BOOST_TEST( bind(f_7, _1, 2, 3, 4, 5, 6, 7)(i) == 7654321L );
  79. BOOST_TEST( bind(f_8, _1, 2, 3, 4, 5, 6, 7, 8)(i) == 87654321L );
  80. BOOST_TEST( bind(f_9, _1, 2, 3, 4, 5, 6, 7, 8, 9)(i) == 987654321L );
  81. }
  82. int main()
  83. {
  84. function_test();
  85. return boost::report_errors();
  86. }