ptr_map_adapter.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // Boost.Pointer Container
  3. //
  4. // Copyright Thorsten Ottosen 2003-2005. Use, modification and
  5. // distribution is subject to the Boost Software License, Version
  6. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // For more information, see http://www.boost.org/libs/ptr_container/
  10. //
  11. #include "test_data.hpp"
  12. #include <boost/ptr_container/ptr_map.hpp>
  13. #include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp>
  14. #include <boost/test/unit_test.hpp>
  15. #include <string>
  16. using namespace std;
  17. #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
  18. #pragma GCC diagnostic push
  19. #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
  20. #endif
  21. void test_ptr_map_adapter()
  22. {
  23. //typedef_test< ptr_map<int, Base>, Derived >();
  24. //typedef_test< ptr_map<int, Value>, Value >();
  25. //associative_container_test< ptr_map<int, Base>, Base, Derived >();
  26. //associative_container_test< ptr_map<int, Value>, Value, Value >();
  27. //typedef_test< ptr_multimap<int, Base>, Derived >();
  28. //typedef_test< ptr_multimap<int, Value>, Value >();
  29. //associative_container_test< ptr_multimap<int, Base>, Base, Derived >();
  30. //associative_container_test< ptr_multimap<int, Value>, Value, Value >();
  31. string joe = "joe";
  32. string brian = "brian";
  33. ptr_map<string,int> m;
  34. m.insert( joe, new int( 4 ) );
  35. #ifndef BOOST_NO_AUTO_PTR
  36. m.insert( brian, std::auto_ptr<int>( new int( 6 ) ) );
  37. #endif
  38. #ifndef BOOST_NO_CXX11_SMART_PTR
  39. m.insert( brian, std::unique_ptr<int>( new int( 6 ) ) );
  40. #endif
  41. m[ joe ] += 56;
  42. m[ brian ] += 10;
  43. try
  44. {
  45. m[ "hans" ] = 4;
  46. }
  47. catch( const bad_ptr_container_operation& )
  48. { }
  49. ptr_map<string,int> m2;
  50. m2.insert( m2.begin(), *m.begin() );
  51. BOOST_CHECK( m != m2 );
  52. BOOST_CHECK( m2 < m );
  53. m2.insert( m2.begin(), joe, new int(5) );
  54. BOOST_CHECK( m != m2 );
  55. BOOST_CHECK( m2 > m );
  56. ptr_multimap<string,int> m3;
  57. m3.insert( m3.begin(), *m.begin() );
  58. BOOST_CHECK( m3.size() == 1u );
  59. m3.insert( m3.begin(), brian, new int(11 ) );
  60. BOOST_CHECK( m3.size() == 2u );
  61. }
  62. #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
  63. #pragma GCC diagnostic pop
  64. #endif
  65. using boost::unit_test::test_suite;
  66. test_suite* init_unit_test_suite( int argc, char* argv[] )
  67. {
  68. test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" );
  69. test->add( BOOST_TEST_CASE( &test_ptr_map_adapter ) );
  70. return test;
  71. }