bind_fnobj2_test.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*==============================================================================
  2. Copyright (c) 2005, 2008 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. mutable unsigned int hash;
  28. typedef int result_type;
  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 boost::phoenix::bind;
  44. using boost::phoenix::ref;
  45. X x;
  46. bind(ref(x) )();
  47. bind(ref(x), 1 )();
  48. bind(ref(x), 1, 2 )();
  49. bind(ref(x), 1, 2, 3 )();
  50. bind(ref(x), 1, 2, 3, 4 )();
  51. bind(ref(x), 1, 2, 3, 4, 5 )();
  52. bind(ref(x), 1, 2, 3, 4, 5, 6 )();
  53. bind(ref(x), 1, 2, 3, 4, 5, 6, 7)();
  54. bind(ref(x), 1, 2, 3, 4, 5, 6, 7, 8 )();
  55. bind(ref(x), 1, 2, 3, 4, 5, 6, 7, 8, 9 )();
  56. BOOST_TEST( x.hash == 9932 );
  57. }
  58. int main()
  59. {
  60. function_object_test();
  61. return boost::report_errors();
  62. }