test_bimap_project.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 <string>
  20. // Boost.Bimap
  21. #include <boost/bimap/bimap.hpp>
  22. #include <boost/bimap/list_of.hpp>
  23. using namespace boost::bimaps;
  24. struct left_tag {};
  25. struct right_tag {};
  26. void test_bimap_project()
  27. {
  28. typedef bimap
  29. <
  30. tagged< int , left_tag >,
  31. list_of< tagged< std::string, right_tag > >
  32. > bm_type;
  33. bm_type bm;
  34. bm.insert( bm_type::value_type(1,"1") );
  35. bm.insert( bm_type::value_type(2,"2") );
  36. bm_type:: iterator iter = bm.begin();
  37. bm_type:: left_iterator left_iter = bm.left.find(1);
  38. bm_type::right_iterator right_iter = bm.right.begin();
  39. const bm_type & cbm = bm;
  40. bm_type:: const_iterator citer = cbm.begin();
  41. bm_type:: left_const_iterator left_citer = cbm.left.find(1);
  42. bm_type::right_const_iterator right_citer = cbm.right.begin();
  43. // non const projection
  44. BOOST_CHECK( bm.project_up (bm.end()) == bm.end() );
  45. BOOST_CHECK( bm.project_left (bm.end()) == bm.left.end() );
  46. BOOST_CHECK( bm.project_right(bm.end()) == bm.right.end() );
  47. BOOST_CHECK( bm.project_up (iter) == iter );
  48. BOOST_CHECK( bm.project_left (iter) == left_iter );
  49. BOOST_CHECK( bm.project_right(iter) == right_iter );
  50. BOOST_CHECK( bm.project_up (left_iter) == iter );
  51. BOOST_CHECK( bm.project_left (left_iter) == left_iter );
  52. BOOST_CHECK( bm.project_right(left_iter) == right_iter );
  53. BOOST_CHECK( bm.project_up (right_iter) == iter );
  54. BOOST_CHECK( bm.project_left (right_iter) == left_iter );
  55. BOOST_CHECK( bm.project_right(right_iter) == right_iter );
  56. bm.project_up ( left_iter)->right = "u";
  57. bm.project_left (right_iter)->second = "l";
  58. bm.project_right( iter)->first = "r";
  59. // const projection
  60. BOOST_CHECK( cbm.project_up (cbm.end()) == cbm.end() );
  61. BOOST_CHECK( cbm.project_left (cbm.end()) == cbm.left.end() );
  62. BOOST_CHECK( cbm.project_right(cbm.end()) == cbm.right.end() );
  63. BOOST_CHECK( cbm.project_up (citer) == citer );
  64. BOOST_CHECK( cbm.project_left (citer) == left_citer );
  65. BOOST_CHECK( cbm.project_right(citer) == right_citer );
  66. BOOST_CHECK( cbm.project_up (left_citer) == citer );
  67. BOOST_CHECK( cbm.project_left (left_citer) == left_citer );
  68. BOOST_CHECK( cbm.project_right(left_citer) == right_citer );
  69. BOOST_CHECK( cbm.project_up (right_citer) == citer );
  70. BOOST_CHECK( cbm.project_left (right_citer) == left_citer );
  71. BOOST_CHECK( cbm.project_right(right_citer) == right_citer );
  72. // mixed projection
  73. BOOST_CHECK( bm.project_up (left_citer) == iter );
  74. BOOST_CHECK( bm.project_left (left_citer) == left_iter );
  75. BOOST_CHECK( bm.project_right(left_citer) == right_iter );
  76. BOOST_CHECK( cbm.project_up (right_iter) == citer );
  77. BOOST_CHECK( cbm.project_left (right_iter) == left_citer );
  78. BOOST_CHECK( cbm.project_right(right_iter) == right_citer );
  79. bm.project_up ( left_citer)->right = "u";
  80. bm.project_left (right_citer)->second = "l";
  81. bm.project_right( citer)->first = "r";
  82. // Support for tags
  83. BOOST_CHECK( bm.project< left_tag>(iter) == left_iter );
  84. BOOST_CHECK( bm.project<right_tag>(iter) == right_iter );
  85. BOOST_CHECK( bm.project< left_tag>(left_iter) == left_iter );
  86. BOOST_CHECK( bm.project<right_tag>(left_iter) == right_iter );
  87. BOOST_CHECK( bm.project< left_tag>(right_iter) == left_iter );
  88. BOOST_CHECK( bm.project<right_tag>(right_iter) == right_iter );
  89. BOOST_CHECK( cbm.project< left_tag>(citer) == left_citer );
  90. BOOST_CHECK( cbm.project<right_tag>(citer) == right_citer );
  91. BOOST_CHECK( cbm.project< left_tag>(left_citer) == left_citer );
  92. BOOST_CHECK( cbm.project<right_tag>(left_citer) == right_citer );
  93. BOOST_CHECK( cbm.project< left_tag>(right_citer) == left_citer );
  94. BOOST_CHECK( cbm.project<right_tag>(right_citer) == right_citer );
  95. bm.project< left_tag>(right_citer)->second = "l";
  96. bm.project<right_tag>( left_citer)->first = "r";
  97. }
  98. int test_main( int, char* [] )
  99. {
  100. test_bimap_project();
  101. return 0;
  102. }