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 9 // VC++ 8.0 warns on usage of certain Standard Library and API functions that 10 // can be cause buffer overruns or other possible security issues if misused. 11 // See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx 12 // But the wording of the warning is misleading and unsettling, there are no 13 // portable alternative functions, and VC++ 8.0's own libraries use the 14 // functions in question. So turn off the warnings. 15 #define _CRT_SECURE_NO_DEPRECATE 16 #define _SCL_SECURE_NO_DEPRECATE 17 18 #include <boost/config.hpp> 19 20 #include <boost/core/lightweight_test.hpp> 21 22 #include <string> 23 24 // Boost.Bimap 25 #include <boost/bimap/bimap.hpp> 26 #include <boost/bimap/list_of.hpp> 27 28 using namespace boost::bimaps; 29 30 struct left_tag {}; 31 struct right_tag {}; 32 test_bimap_project()33void test_bimap_project() 34 { 35 typedef bimap 36 < 37 tagged< int , left_tag >, 38 list_of< tagged< std::string, right_tag > > 39 40 > bm_type; 41 42 bm_type bm; 43 44 bm.insert( bm_type::value_type(1,"1") ); 45 bm.insert( bm_type::value_type(2,"2") ); 46 47 bm_type:: iterator iter = bm.begin(); 48 bm_type:: left_iterator left_iter = bm.left.find(1); 49 bm_type::right_iterator right_iter = bm.right.begin(); 50 51 const bm_type & cbm = bm; 52 53 bm_type:: const_iterator citer = cbm.begin(); 54 bm_type:: left_const_iterator left_citer = cbm.left.find(1); 55 bm_type::right_const_iterator right_citer = cbm.right.begin(); 56 57 // non const projection 58 59 BOOST_TEST( bm.project_up (bm.end()) == bm.end() ); 60 BOOST_TEST( bm.project_left (bm.end()) == bm.left.end() ); 61 BOOST_TEST( bm.project_right(bm.end()) == bm.right.end() ); 62 63 BOOST_TEST( bm.project_up (iter) == iter ); 64 BOOST_TEST( bm.project_left (iter) == left_iter ); 65 BOOST_TEST( bm.project_right(iter) == right_iter ); 66 67 BOOST_TEST( bm.project_up (left_iter) == iter ); 68 BOOST_TEST( bm.project_left (left_iter) == left_iter ); 69 BOOST_TEST( bm.project_right(left_iter) == right_iter ); 70 71 BOOST_TEST( bm.project_up (right_iter) == iter ); 72 BOOST_TEST( bm.project_left (right_iter) == left_iter ); 73 BOOST_TEST( bm.project_right(right_iter) == right_iter ); 74 75 bm.project_up ( left_iter)->right = "u"; 76 bm.project_left (right_iter)->second = "l"; 77 bm.project_right( iter)->first = "r"; 78 79 // const projection 80 81 BOOST_TEST( cbm.project_up (cbm.end()) == cbm.end() ); 82 BOOST_TEST( cbm.project_left (cbm.end()) == cbm.left.end() ); 83 BOOST_TEST( cbm.project_right(cbm.end()) == cbm.right.end() ); 84 85 BOOST_TEST( cbm.project_up (citer) == citer ); 86 BOOST_TEST( cbm.project_left (citer) == left_citer ); 87 BOOST_TEST( cbm.project_right(citer) == right_citer ); 88 89 BOOST_TEST( cbm.project_up (left_citer) == citer ); 90 BOOST_TEST( cbm.project_left (left_citer) == left_citer ); 91 BOOST_TEST( cbm.project_right(left_citer) == right_citer ); 92 93 BOOST_TEST( cbm.project_up (right_citer) == citer ); 94 BOOST_TEST( cbm.project_left (right_citer) == left_citer ); 95 BOOST_TEST( cbm.project_right(right_citer) == right_citer ); 96 97 // mixed projection 98 99 BOOST_TEST( bm.project_up (left_citer) == iter ); 100 BOOST_TEST( bm.project_left (left_citer) == left_iter ); 101 BOOST_TEST( bm.project_right(left_citer) == right_iter ); 102 103 BOOST_TEST( cbm.project_up (right_iter) == citer ); 104 BOOST_TEST( cbm.project_left (right_iter) == left_citer ); 105 BOOST_TEST( cbm.project_right(right_iter) == right_citer ); 106 107 bm.project_up ( left_citer)->right = "u"; 108 bm.project_left (right_citer)->second = "l"; 109 bm.project_right( citer)->first = "r"; 110 111 // Support for tags 112 113 BOOST_TEST( bm.project< left_tag>(iter) == left_iter ); 114 BOOST_TEST( bm.project<right_tag>(iter) == right_iter ); 115 116 BOOST_TEST( bm.project< left_tag>(left_iter) == left_iter ); 117 BOOST_TEST( bm.project<right_tag>(left_iter) == right_iter ); 118 119 BOOST_TEST( bm.project< left_tag>(right_iter) == left_iter ); 120 BOOST_TEST( bm.project<right_tag>(right_iter) == right_iter ); 121 122 BOOST_TEST( cbm.project< left_tag>(citer) == left_citer ); 123 BOOST_TEST( cbm.project<right_tag>(citer) == right_citer ); 124 125 BOOST_TEST( cbm.project< left_tag>(left_citer) == left_citer ); 126 BOOST_TEST( cbm.project<right_tag>(left_citer) == right_citer ); 127 128 BOOST_TEST( cbm.project< left_tag>(right_citer) == left_citer ); 129 BOOST_TEST( cbm.project<right_tag>(right_citer) == right_citer ); 130 131 bm.project< left_tag>(right_citer)->second = "l"; 132 bm.project<right_tag>( left_citer)->first = "r"; 133 134 } 135 136 main()137int main() 138 { 139 test_bimap_project(); 140 return boost::report_errors(); 141 } 142 143