bind_rel_test.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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_rel_test.cpp - ==, !=, <, <=, >, >= operators
  10. //
  11. // Copyright (c) 2005 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. 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. int x = 4;
  37. int y = x + x;
  38. // bind op value
  39. BOOST_TEST( ( boost::bind( f, _1 ) == y )( x ) );
  40. BOOST_TEST( !( ( boost::bind( f, _1 ) != y )( x ) ) );
  41. BOOST_TEST( !( ( boost::bind( f, _1 ) < y )( x ) ) );
  42. BOOST_TEST( ( boost::bind( f, _1 ) < y + 1 )( x ) );
  43. BOOST_TEST( !( ( boost::bind( f, _1 ) > y )( x ) ) );
  44. BOOST_TEST( ( boost::bind( f, _1 ) > y - 1 )( x ) );
  45. BOOST_TEST( !( ( boost::bind( f, _1 ) <= y - 1 )( x ) ) );
  46. BOOST_TEST( ( boost::bind( f, _1 ) <= y )( x ) );
  47. BOOST_TEST( ( boost::bind( f, _1 ) <= y + 1 )( x ) );
  48. BOOST_TEST( !( ( boost::bind( f, _1 ) >= y + 1 )( x ) ) );
  49. BOOST_TEST( ( boost::bind( f, _1 ) >= y )( x ) );
  50. BOOST_TEST( ( boost::bind( f, _1 ) >= y - 1 )( x ) );
  51. // bind op ref
  52. BOOST_TEST( ( boost::bind( f, _1 ) == boost::ref( y ) )( x ) );
  53. BOOST_TEST( !( ( boost::bind( f, _1 ) != boost::ref( y ) )( x ) ) );
  54. BOOST_TEST( !( ( boost::bind( f, _1 ) < boost::ref( y ) )( x ) ) );
  55. BOOST_TEST( !( ( boost::bind( f, _1 ) > boost::ref( y ) )( x ) ) );
  56. BOOST_TEST( ( boost::bind( f, _1 ) <= boost::ref( y ) )( x ) );
  57. BOOST_TEST( ( boost::bind( f, _1 ) >= boost::ref( y ) )( x ) );
  58. // bind op placeholder
  59. BOOST_TEST( ( boost::bind( f, _1 ) == _2 )( x, y ) );
  60. BOOST_TEST( !( ( boost::bind( f, _1 ) != _2 )( x, y ) ) );
  61. BOOST_TEST( !( ( boost::bind( f, _1 ) < _2 )( x, y ) ) );
  62. BOOST_TEST( !( ( boost::bind( f, _1 ) > _2 )( x, y ) ) );
  63. BOOST_TEST( ( boost::bind( f, _1 ) <= _2 )( x, y ) );
  64. BOOST_TEST( ( boost::bind( f, _1 ) >= _2 )( x, y ) );
  65. // bind op bind
  66. // important: bind( f, _1 ) and bind( g, _1 ) have the same type
  67. BOOST_TEST( ( boost::bind( f, _1 ) == boost::bind( g, _1 ) )( x ) );
  68. BOOST_TEST( !( ( boost::bind( f, _1 ) != boost::bind( g, _1 ) )( x ) ) );
  69. BOOST_TEST( !( ( boost::bind( f, _1 ) < boost::bind( g, _1 ) )( x ) ) );
  70. BOOST_TEST( ( boost::bind( f, _1 ) <= boost::bind( g, _1 ) )( x ) );
  71. BOOST_TEST( !( ( boost::bind( f, _1 ) > boost::bind( g, _1 ) )( x ) ) );
  72. BOOST_TEST( ( boost::bind( f, _1 ) >= boost::bind( g, _1 ) )( x ) );
  73. return boost::report_errors();
  74. }