test_bimap_ordered.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. #define BOOST_BIMAP_DISABLE_SERIALIZATION
  18. // Boost.Test
  19. #include <boost/test/minimal.hpp>
  20. // std
  21. #include <set>
  22. #include <map>
  23. #include <string>
  24. #include <functional>
  25. // Set type specifications
  26. #include <boost/bimap/set_of.hpp>
  27. #include <boost/bimap/multiset_of.hpp>
  28. // bimap container
  29. #include <boost/bimap/bimap.hpp>
  30. #include <libs/bimap/test/test_bimap.hpp>
  31. struct left_tag {};
  32. struct right_tag {};
  33. void test_bimap()
  34. {
  35. using namespace boost::bimaps;
  36. typedef std::map<int,double> left_data_type;
  37. left_data_type left_data;
  38. left_data.insert( left_data_type::value_type(1,0.1) );
  39. left_data.insert( left_data_type::value_type(2,0.2) );
  40. left_data.insert( left_data_type::value_type(3,0.3) );
  41. left_data.insert( left_data_type::value_type(4,0.4) );
  42. typedef std::map<double,int> right_data_type;
  43. right_data_type right_data;
  44. right_data.insert( right_data_type::value_type(0.1,1) );
  45. right_data.insert( right_data_type::value_type(0.2,2) );
  46. right_data.insert( right_data_type::value_type(0.3,3) );
  47. right_data.insert( right_data_type::value_type(0.4,4) );
  48. //--------------------------------------------------------------------
  49. {
  50. typedef bimap< int, double > bm_type;
  51. std::set< bm_type::value_type > data;
  52. data.insert( bm_type::value_type(1,0.1) );
  53. data.insert( bm_type::value_type(2,0.2) );
  54. data.insert( bm_type::value_type(3,0.3) );
  55. data.insert( bm_type::value_type(4,0.4) );
  56. bm_type bm;
  57. test_set_set_bimap(bm,data,left_data,right_data);
  58. }
  59. //--------------------------------------------------------------------
  60. //--------------------------------------------------------------------
  61. {
  62. typedef bimap
  63. <
  64. multiset_of< tagged<int, left_tag > >,
  65. multiset_of< tagged<double, right_tag > >,
  66. multiset_of_relation< std::less< _relation > >
  67. > bm_type;
  68. std::set< bm_type::value_type > data;
  69. data.insert( bm_type::value_type(1,0.1) );
  70. data.insert( bm_type::value_type(2,0.2) );
  71. data.insert( bm_type::value_type(3,0.3) );
  72. data.insert( bm_type::value_type(4,0.4) );
  73. bm_type bm;
  74. test_multiset_multiset_bimap(bm,data,left_data,right_data);
  75. test_tagged_bimap<left_tag,right_tag>(bm,data);
  76. }
  77. //--------------------------------------------------------------------
  78. //--------------------------------------------------------------------
  79. {
  80. typedef bimap<int,double,right_based> bm_type;
  81. std::set< bm_type::value_type > data;
  82. data.insert( bm_type::value_type(1,0.1) );
  83. data.insert( bm_type::value_type(2,0.2) );
  84. data.insert( bm_type::value_type(3,0.3) );
  85. data.insert( bm_type::value_type(4,0.4) );
  86. bm_type bm;
  87. test_set_set_bimap(bm,data,left_data,right_data);
  88. }
  89. //--------------------------------------------------------------------
  90. //--------------------------------------------------------------------
  91. {
  92. typedef bimap
  93. <
  94. multiset_of< int, std::greater<int> >, set_of<std::string> ,
  95. multiset_of_relation< std::greater< _relation > >
  96. > bimap_type;
  97. bimap_type b1;
  98. b1.insert( bimap_type::value_type(1,"one") );
  99. bimap_type b2( b1 );
  100. BOOST_CHECK( b1 == b2 );
  101. BOOST_CHECK( ! ( b1 != b2 ) );
  102. BOOST_CHECK( b1 <= b2 );
  103. BOOST_CHECK( b1 >= b2 );
  104. BOOST_CHECK( ! ( b1 < b2 ) );
  105. BOOST_CHECK( ! ( b1 > b2 ) );
  106. b1.insert( bimap_type::value_type(2,"two") );
  107. b2 = b1;
  108. BOOST_CHECK( b2 == b1 );
  109. b1.insert( bimap_type::value_type(3,"three") );
  110. b2.left = b1.left;
  111. BOOST_CHECK( b2 == b1 );
  112. b1.insert( bimap_type::value_type(4,"four") );
  113. b2.right = b1.right;
  114. BOOST_CHECK( b2 == b1 );
  115. b1.clear();
  116. b2.swap(b1);
  117. BOOST_CHECK( b2.empty() && !b1.empty() );
  118. b1.left.swap( b2.left );
  119. BOOST_CHECK( b1.empty() && !b2.empty() );
  120. b1.right.swap( b2.right );
  121. BOOST_CHECK( b2.empty() && !b1.empty() );
  122. }
  123. //--------------------------------------------------------------------
  124. }
  125. int test_main( int, char* [] )
  126. {
  127. test_bimap();
  128. return 0;
  129. }