bind_fastcall_test.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #include <boost/config.hpp>
  2. #ifndef BOOST_MSVC
  3. int main()
  4. {
  5. }
  6. #else
  7. #if defined(BOOST_MSVC)
  8. #pragma warning(disable: 4786) // identifier truncated in debug info
  9. #pragma warning(disable: 4710) // function not inlined
  10. #pragma warning(disable: 4711) // function selected for automatic inline expansion
  11. #pragma warning(disable: 4514) // unreferenced inline removed
  12. #endif
  13. //
  14. // bind_fastcall_test.cpp - test for bind.hpp + __fastcall (free functions)
  15. //
  16. // Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
  17. //
  18. // Distributed under the Boost Software License, Version 1.0. (See
  19. // accompanying file LICENSE_1_0.txt or copy at
  20. // http://www.boost.org/LICENSE_1_0.txt)
  21. //
  22. #define BOOST_BIND_ENABLE_FASTCALL
  23. #include <boost/bind.hpp>
  24. #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
  25. #pragma warning(push, 3)
  26. #endif
  27. #include <iostream>
  28. #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
  29. #pragma warning(pop)
  30. #endif
  31. #include <boost/detail/lightweight_test.hpp>
  32. //
  33. long __fastcall f_0()
  34. {
  35. return 17041L;
  36. }
  37. long __fastcall f_1(long a)
  38. {
  39. return a;
  40. }
  41. long __fastcall f_2(long a, long b)
  42. {
  43. return a + 10 * b;
  44. }
  45. long __fastcall f_3(long a, long b, long c)
  46. {
  47. return a + 10 * b + 100 * c;
  48. }
  49. long __fastcall f_4(long a, long b, long c, long d)
  50. {
  51. return a + 10 * b + 100 * c + 1000 * d;
  52. }
  53. long __fastcall f_5(long a, long b, long c, long d, long e)
  54. {
  55. return a + 10 * b + 100 * c + 1000 * d + 10000 * e;
  56. }
  57. long __fastcall f_6(long a, long b, long c, long d, long e, long f)
  58. {
  59. return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f;
  60. }
  61. long __fastcall f_7(long a, long b, long c, long d, long e, long f, long g)
  62. {
  63. return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g;
  64. }
  65. long __fastcall f_8(long a, long b, long c, long d, long e, long f, long g, long h)
  66. {
  67. return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h;
  68. }
  69. long __fastcall f_9(long a, long b, long c, long d, long e, long f, long g, long h, long i)
  70. {
  71. return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
  72. }
  73. void function_test()
  74. {
  75. using namespace boost;
  76. int const i = 1;
  77. BOOST_TEST( bind(f_0)(i) == 17041L );
  78. BOOST_TEST( bind(f_1, _1)(i) == 1L );
  79. BOOST_TEST( bind(f_2, _1, 2)(i) == 21L );
  80. BOOST_TEST( bind(f_3, _1, 2, 3)(i) == 321L );
  81. BOOST_TEST( bind(f_4, _1, 2, 3, 4)(i) == 4321L );
  82. BOOST_TEST( bind(f_5, _1, 2, 3, 4, 5)(i) == 54321L );
  83. BOOST_TEST( bind(f_6, _1, 2, 3, 4, 5, 6)(i) == 654321L );
  84. BOOST_TEST( bind(f_7, _1, 2, 3, 4, 5, 6, 7)(i) == 7654321L );
  85. BOOST_TEST( bind(f_8, _1, 2, 3, 4, 5, 6, 7, 8)(i) == 87654321L );
  86. BOOST_TEST( bind(f_9, _1, 2, 3, 4, 5, 6, 7, 8, 9)(i) == 987654321L );
  87. }
  88. int main()
  89. {
  90. function_test();
  91. return boost::report_errors();
  92. }
  93. #endif