bind_fnobj2_test.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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_fnobj2_test.cpp - test for function objects w/ the type<> syntax
  10. //
  11. // Copyright (c) 2005, 2008 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. mutable unsigned int hash;
  29. X(): hash(0) {}
  30. int operator()() const { operator()(17); return 0; }
  31. int operator()(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
  32. int operator()(int a1, int a2) const { operator()(a1); operator()(a2); return 0; }
  33. int operator()(int a1, int a2, int a3) const { operator()(a1, a2); operator()(a3); return 0; }
  34. int operator()(int a1, int a2, int a3, int a4) const { operator()(a1, a2, a3); operator()(a4); return 0; }
  35. int operator()(int a1, int a2, int a3, int a4, int a5) const { operator()(a1, a2, a3, a4); operator()(a5); return 0; }
  36. int operator()(int a1, int a2, int a3, int a4, int a5, int a6) const { operator()(a1, a2, a3, a4, a5); operator()(a6); return 0; }
  37. int operator()(int a1, int a2, int a3, int a4, int a5, int a6, int a7) const { operator()(a1, a2, a3, a4, a5, a6); operator()(a7); return 0; }
  38. int operator()(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) const { operator()(a1, a2, a3, a4, a5, a6, a7); operator()(a8); return 0; }
  39. int operator()(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9) const { operator()(a1, a2, a3, a4, a5, a6, a7, a8); operator()(a9); return 0; }
  40. };
  41. void function_object_test()
  42. {
  43. using namespace boost;
  44. X x;
  45. bind( type<void>(), ref(x) )();
  46. bind( type<void>(), ref(x), 1 )();
  47. bind( type<void>(), ref(x), 1, 2 )();
  48. bind( type<void>(), ref(x), 1, 2, 3 )();
  49. bind( type<void>(), ref(x), 1, 2, 3, 4 )();
  50. bind( type<void>(), ref(x), 1, 2, 3, 4, 5 )();
  51. bind( type<void>(), ref(x), 1, 2, 3, 4, 5, 6 )();
  52. bind( type<void>(), ref(x), 1, 2, 3, 4, 5, 6, 7)();
  53. bind( type<void>(), ref(x), 1, 2, 3, 4, 5, 6, 7, 8 )();
  54. bind( type<void>(), ref(x), 1, 2, 3, 4, 5, 6, 7, 8, 9 )();
  55. BOOST_TEST( x.hash == 9932 );
  56. }
  57. int main()
  58. {
  59. function_object_test();
  60. return boost::report_errors();
  61. }