bind_function_test.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*==============================================================================
  2. Copyright (c) 2005 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. #include <boost/detail/lightweight_test.hpp>
  18. #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
  19. #pragma warning(push, 3)
  20. #endif
  21. #include <iostream>
  22. #include <boost/function.hpp>
  23. #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
  24. #pragma warning(pop)
  25. #endif
  26. int f( int x )
  27. {
  28. return x;
  29. }
  30. int g( int x )
  31. {
  32. return x + 1;
  33. }
  34. int main()
  35. {
  36. using boost::phoenix::bind;
  37. boost::function0<int> fn;
  38. BOOST_TEST( !fn.contains( bind( f, 1 ) ) );
  39. BOOST_TEST( !fn.contains( bind( f, 2 ) ) );
  40. BOOST_TEST( !fn.contains( bind( g, 1 ) ) );
  41. fn = bind( f, 1 );
  42. BOOST_TEST( fn() == 1 );
  43. BOOST_TEST( fn.contains( bind( f, 1 ) ) );
  44. BOOST_TEST( !fn.contains( bind( f, 2 ) ) );
  45. BOOST_TEST( !fn.contains( bind( g, 1 ) ) );
  46. fn = bind( f, 2 );
  47. BOOST_TEST( fn() == 2 );
  48. BOOST_TEST( !fn.contains( bind( f, 1 ) ) );
  49. BOOST_TEST( fn.contains( bind( f, 2 ) ) );
  50. BOOST_TEST( !fn.contains( bind( g, 1 ) ) );
  51. fn = bind( g, 1 );
  52. BOOST_TEST( fn() == 2 );
  53. BOOST_TEST( !fn.contains( bind( f, 1 ) ) );
  54. BOOST_TEST( !fn.contains( bind( f, 2 ) ) );
  55. BOOST_TEST( fn.contains( bind( g, 1 ) ) );
  56. return boost::report_errors();
  57. }