const_ranges.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Boost.Range library
  2. //
  3. // Copyright Thorsten Ottosen 2003-2004. Use, modification and
  4. // distribution is subject to the Boost Software License, Version
  5. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // For more information, see http://www.boost.org/libs/range/
  9. //
  10. #include <boost/detail/workaround.hpp>
  11. #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
  12. # pragma warn -8091 // suppress warning in Boost.Test
  13. # pragma warn -8057 // unused argument argc/argv in Boost.Test
  14. #endif
  15. #include <boost/range.hpp>
  16. #include <boost/test/test_tools.hpp>
  17. #include <boost/test/unit_test.hpp>
  18. #include <string>
  19. template< class T >
  20. const T& as_const( const T& r )
  21. {
  22. return r;
  23. }
  24. void check_const_ranges()
  25. {
  26. std::string foo( "foo" );
  27. const std::string bar( "bar" );
  28. BOOST_CHECK( boost::const_begin( foo ) == boost::begin( as_const( foo ) ) );
  29. BOOST_CHECK( boost::const_end( foo ) == boost::end( as_const( foo ) ) );
  30. BOOST_CHECK( boost::const_rbegin( foo ) == boost::rbegin( as_const( foo ) ) );
  31. BOOST_CHECK( boost::const_rend( foo ) == boost::rend( as_const( foo ) ) );
  32. BOOST_CHECK( boost::const_begin( bar ) == boost::begin( as_const( bar ) ) );
  33. BOOST_CHECK( boost::const_end( bar ) == boost::end( as_const( bar ) ) );
  34. BOOST_CHECK( boost::const_rbegin( bar ) == boost::rbegin( as_const( bar ) ) );
  35. BOOST_CHECK( boost::const_rend( bar ) == boost::rend( as_const( bar ) ) );
  36. }
  37. boost::unit_test::test_suite* init_unit_test_suite( int argc, char* argv[] )
  38. {
  39. boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" );
  40. test->add( BOOST_TEST_CASE( &check_const_ranges ) );
  41. return test;
  42. }