test_bimap_mutable.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Boost.Bimap
  2. //
  3. // Copyright (c) 2006-2007 Matias Capeletto
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. // VC++ 8.0 warns on usage of certain Standard Library and API functions that
  9. // can be cause buffer overruns or other possible security issues if misused.
  10. // See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx
  11. // But the wording of the warning is misleading and unsettling, there are no
  12. // portable alternative functions, and VC++ 8.0's own libraries use the
  13. // functions in question. So turn off the warnings.
  14. #define _CRT_SECURE_NO_DEPRECATE
  15. #define _SCL_SECURE_NO_DEPRECATE
  16. #include <boost/config.hpp>
  17. // Boost.Test
  18. #include <boost/test/minimal.hpp>
  19. // Boost.Bimap
  20. #include <boost/bimap/bimap.hpp>
  21. #include <boost/bimap/list_of.hpp>
  22. #include <boost/bimap/vector_of.hpp>
  23. #include <boost/bimap/unconstrained_set_of.hpp>
  24. using namespace boost::bimaps;
  25. template< class BimapType >
  26. void test_bimap_mutable()
  27. {
  28. typedef BimapType bm_type;
  29. bm_type bm;
  30. bm.insert( BOOST_DEDUCED_TYPENAME bm_type::value_type(1,0.1) );
  31. const bm_type & cbm = bm;
  32. // Map Mutable Iterator test
  33. {
  34. BOOST_DEDUCED_TYPENAME bm_type::left_iterator iter = bm.left.begin();
  35. iter->second = 0.2;
  36. BOOST_CHECK( iter->second == bm.left.begin()->second );
  37. BOOST_DEDUCED_TYPENAME bm_type::left_const_iterator citer = bm.left.begin();
  38. BOOST_CHECK( citer->second == bm.left.begin()->second );
  39. BOOST_DEDUCED_TYPENAME bm_type::left_const_iterator cciter = cbm.left.begin();
  40. BOOST_CHECK( cciter->second == cbm.left.begin()->second );
  41. }
  42. // Set Mutable Iterator test
  43. {
  44. BOOST_DEDUCED_TYPENAME bm_type::iterator iter = bm.begin();
  45. iter->right = 0.1;
  46. BOOST_CHECK( iter->right == bm.begin()->right );
  47. BOOST_DEDUCED_TYPENAME bm_type::const_iterator citer = bm.begin();
  48. BOOST_CHECK( citer->right == bm.begin()->right );
  49. BOOST_DEDUCED_TYPENAME bm_type::const_iterator cciter = cbm.begin();
  50. BOOST_CHECK( cciter->left == cbm.begin()->left );
  51. }
  52. // Map Assignable Reference test
  53. {
  54. BOOST_DEDUCED_TYPENAME bm_type::left_reference r = *bm.left.begin();
  55. r.second = 0.2;
  56. BOOST_CHECK( r == *bm.left.begin() );
  57. BOOST_DEDUCED_TYPENAME bm_type::left_const_reference cr = *bm.left.begin();
  58. BOOST_CHECK( cr == *bm.left.begin() );
  59. BOOST_DEDUCED_TYPENAME bm_type::left_const_reference ccr = *cbm.left.begin();
  60. BOOST_CHECK( ccr == *cbm.left.begin() );
  61. }
  62. // Set Assignable Reference test
  63. {
  64. BOOST_DEDUCED_TYPENAME bm_type::reference r = *bm.begin();
  65. r.right = 0.1;
  66. BOOST_CHECK( r == *bm.begin() );
  67. BOOST_DEDUCED_TYPENAME bm_type::const_reference cr = *bm.begin();
  68. BOOST_CHECK( cr == *bm.begin() );
  69. BOOST_DEDUCED_TYPENAME bm_type::const_reference ccr = *cbm.begin();
  70. BOOST_CHECK( ccr == *bm.begin() );
  71. }
  72. }
  73. int test_main( int, char* [] )
  74. {
  75. test_bimap_mutable< bimap< int, list_of<double> > >();
  76. test_bimap_mutable< bimap< int, vector_of<double> > >();
  77. test_bimap_mutable< bimap< int, unconstrained_set_of<double> > >();
  78. return 0;
  79. }