test_bimap_info.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. #include <boost/config.hpp>
  20. #include <string>
  21. #include <boost/bimap/bimap.hpp>
  22. #include <boost/bimap/unordered_set_of.hpp>
  23. int test_bimap_info()
  24. {
  25. using namespace boost::bimaps;
  26. typedef bimap< double, unordered_set_of<int>, with_info<std::string> > bm_type;
  27. bm_type bm;
  28. const bm_type & cbm = bm;
  29. // Insertion with info
  30. bm .insert( bm_type:: value_type(1.1 , 1, "one" ) );
  31. bm.left .insert( bm_type:: left_value_type(2.2 , 2, "two" ) );
  32. bm.right.insert( bm_type::right_value_type( 3 , 3.3, "three" ) );
  33. bm.begin()->info = "1";
  34. BOOST_CHECK( bm.right.find(1)->info == "1" );
  35. bm.left.find(2.2)->info = "2";
  36. BOOST_CHECK( bm.right.find(2)->info == "2" );
  37. bm.right.find(3)->info = "3";
  38. BOOST_CHECK( bm.right.find(3)->info == "3" );
  39. // Empty info insert
  40. bm .insert( bm_type:: value_type(4.4 , 4) );
  41. bm. left.insert( bm_type:: left_value_type(5.5 , 5) );
  42. bm.right.insert( bm_type::right_value_type( 6 , 6.6) );
  43. BOOST_CHECK( bm.right.find(4)->info == "" );
  44. bm.left.info_at(4.4) = "4";
  45. BOOST_CHECK( bm.right.info_at(4) == "4" );
  46. BOOST_CHECK( cbm.right.info_at(4) == "4" );
  47. bm.right.info_at(5) = "5";
  48. BOOST_CHECK( bm.left.info_at(5.5) == "5" );
  49. BOOST_CHECK( cbm.left.info_at(5.5) == "5" );
  50. return 0;
  51. }
  52. struct left {};
  53. struct right {};
  54. struct info {};
  55. int test_tagged_bimap_info()
  56. {
  57. using namespace boost::bimaps;
  58. typedef bimap< tagged<int,left>,
  59. tagged<int,right>,
  60. with_info<tagged<int,info> > > bm_type;
  61. bm_type bm;
  62. const bm_type & cbm = bm;
  63. bm .insert( bm_type:: value_type(1,1,1) );
  64. bm.left .insert( bm_type:: left_value_type(2,2,2) );
  65. bm.right.insert( bm_type::right_value_type(3,3,3) );
  66. bm.begin()->get<info>() = 10;
  67. BOOST_CHECK( bm.right.find(1)->get<info>() == 10 );
  68. BOOST_CHECK( cbm.right.find(1)->get<info>() == 10 );
  69. bm.left.find(2)->get<info>() = 20;
  70. BOOST_CHECK( bm.right.find(2)->get<info>() == 20 );
  71. BOOST_CHECK( cbm.right.find(2)->get<info>() == 20 );
  72. bm.right.find(3)->get<info>() = 30;
  73. BOOST_CHECK( bm.right.find(3)->get<info>() == 30 );
  74. BOOST_CHECK( cbm.right.find(3)->get<info>() == 30 );
  75. // Empty info insert
  76. bm .insert( bm_type:: value_type(4,4) );
  77. bm. left.insert( bm_type:: left_value_type(5,5) );
  78. bm.right.insert( bm_type::right_value_type(6,6) );
  79. bm.left.info_at(4) = 4;
  80. BOOST_CHECK( bm.right.info_at(4) == 4 );
  81. BOOST_CHECK( cbm.right.info_at(4) == 4 );
  82. bm.right.info_at(5) = 5;
  83. BOOST_CHECK( bm.left.info_at(5) == 5 );
  84. BOOST_CHECK( cbm.left.info_at(5) == 5 );
  85. return 0;
  86. }
  87. int test_main( int, char* [] )
  88. {
  89. test_bimap_info();
  90. test_tagged_bimap_info();
  91. return 0;
  92. }