bind_rel_test.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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/phoenix/operator.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. int f( int x )
  27. {
  28. return x + x;
  29. }
  30. int g( int x )
  31. {
  32. return 2 * x;
  33. }
  34. int main()
  35. {
  36. using boost::phoenix::bind;
  37. using boost::phoenix::ref;
  38. using boost::phoenix::placeholders::_1;
  39. using boost::phoenix::placeholders::_2;
  40. int x = 4;
  41. int y = x + x;
  42. // bind op value
  43. BOOST_TEST( ( bind( f, _1 ) == y )( x ) );
  44. BOOST_TEST( !( ( bind( f, _1 ) != y )( x ) ) );
  45. BOOST_TEST( !( ( bind( f, _1 ) < y )( x ) ) );
  46. BOOST_TEST( ( bind( f, _1 ) < y + 1 )( x ) );
  47. BOOST_TEST( !( ( bind( f, _1 ) > y )( x ) ) );
  48. BOOST_TEST( ( bind( f, _1 ) > y - 1 )( x ) );
  49. BOOST_TEST( !( ( bind( f, _1 ) <= y - 1 )( x ) ) );
  50. BOOST_TEST( ( bind( f, _1 ) <= y )( x ) );
  51. BOOST_TEST( ( bind( f, _1 ) <= y + 1 )( x ) );
  52. BOOST_TEST( !( ( bind( f, _1 ) >= y + 1 )( x ) ) );
  53. BOOST_TEST( ( bind( f, _1 ) >= y )( x ) );
  54. BOOST_TEST( ( bind( f, _1 ) >= y - 1 )( x ) );
  55. // bind op ref
  56. BOOST_TEST( ( bind( f, _1 ) == ref( y ) )( x ) );
  57. BOOST_TEST( !( ( bind( f, _1 ) != ref( y ) )( x ) ) );
  58. BOOST_TEST( !( ( bind( f, _1 ) < ref( y ) )( x ) ) );
  59. BOOST_TEST( !( ( bind( f, _1 ) > ref( y ) )( x ) ) );
  60. BOOST_TEST( ( bind( f, _1 ) <= ref( y ) )( x ) );
  61. BOOST_TEST( ( bind( f, _1 ) >= ref( y ) )( x ) );
  62. // bind op placeholder
  63. BOOST_TEST( ( bind( f, _1 ) == _2 )( x, y ) );
  64. BOOST_TEST( !( ( bind( f, _1 ) != _2 )( x, y ) ) );
  65. BOOST_TEST( !( ( bind( f, _1 ) < _2 )( x, y ) ) );
  66. BOOST_TEST( !( ( bind( f, _1 ) > _2 )( x, y ) ) );
  67. BOOST_TEST( ( bind( f, _1 ) <= _2 )( x, y ) );
  68. BOOST_TEST( ( bind( f, _1 ) >= _2 )( x, y ) );
  69. // bind op bind
  70. BOOST_TEST( ( bind( f, _1 ) == bind( g, _1 ) )( x ) );
  71. BOOST_TEST( !( ( bind( f, _1 ) != bind( g, _1 ) )( x ) ) );
  72. BOOST_TEST( !( ( bind( f, _1 ) < bind( g, _1 ) )( x ) ) );
  73. BOOST_TEST( ( bind( f, _1 ) <= bind( g, _1 ) )( x ) );
  74. BOOST_TEST( !( ( bind( f, _1 ) > bind( g, _1 ) )( x ) ) );
  75. BOOST_TEST( ( bind( f, _1 ) >= bind( g, _1 ) )( x ) );
  76. return boost::report_errors();
  77. }