| 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 | // Boost.Bimap |
| 23 | #include <boost/bimap/bimap.hpp> |
| 24 | #include <boost/bimap/list_of.hpp> |
| 25 | #include <boost/bimap/vector_of.hpp> |
| 26 | #include <boost/bimap/unconstrained_set_of.hpp> |
| 27 | |
| 28 | using namespace boost::bimaps; |
| 29 | |
| 30 | template< class BimapType > |
| 31 | void test_bimap_mutable() |
| 32 | { |
| 33 | typedef BimapType bm_type; |
| 34 | |
| 35 | bm_type bm; |
| 36 | bm.insert( BOOST_DEDUCED_TYPENAME bm_type::value_type(1,0.1) ); |
| 37 | |
| 38 | const bm_type & cbm = bm; |
| 39 | |
| 40 | // Map Mutable Iterator test |
| 41 | { |
| 42 | |
| 43 | BOOST_DEDUCED_TYPENAME bm_type::left_iterator iter = bm.left.begin(); |
| 44 | iter->second = 0.2; |
| 45 | BOOST_TEST( iter->second == bm.left.begin()->second ); |
| 46 | |
| 47 | BOOST_DEDUCED_TYPENAME bm_type::left_const_iterator citer = bm.left.begin(); |
| 48 | BOOST_TEST( citer->second == bm.left.begin()->second ); |
| 49 | |
| 50 | BOOST_DEDUCED_TYPENAME bm_type::left_const_iterator cciter = cbm.left.begin(); |
| 51 | BOOST_TEST( cciter->second == cbm.left.begin()->second ); |
| 52 | |
| 53 | } |
| 54 | |
| 55 | // Set Mutable Iterator test |
| 56 | { |
| 57 | |
| 58 | BOOST_DEDUCED_TYPENAME bm_type::iterator iter = bm.begin(); |
| 59 | iter->right = 0.1; |
| 60 | BOOST_TEST( iter->right == bm.begin()->right ); |
| 61 | |
| 62 | BOOST_DEDUCED_TYPENAME bm_type::const_iterator citer = bm.begin(); |
| 63 | BOOST_TEST( citer->right == bm.begin()->right ); |
| 64 | |
| 65 | BOOST_DEDUCED_TYPENAME bm_type::const_iterator cciter = cbm.begin(); |
| 66 | BOOST_TEST( cciter->left == cbm.begin()->left ); |
| 67 | |
| 68 | } |
| 69 | |
| 70 | // Map Assignable Reference test |
| 71 | { |
| 72 | |
| 73 | BOOST_DEDUCED_TYPENAME bm_type::left_reference r = *bm.left.begin(); |
| 74 | r.second = 0.2; |
| 75 | BOOST_TEST( r == *bm.left.begin() ); |
| 76 | |
| 77 | BOOST_DEDUCED_TYPENAME bm_type::left_const_reference cr = *bm.left.begin(); |
| 78 | BOOST_TEST( cr == *bm.left.begin() ); |
| 79 | |
| 80 | BOOST_DEDUCED_TYPENAME bm_type::left_const_reference ccr = *cbm.left.begin(); |
| 81 | BOOST_TEST( ccr == *cbm.left.begin() ); |
| 82 | |
| 83 | } |
| 84 | |
| 85 | // Set Assignable Reference test |
| 86 | { |
| 87 | |
| 88 | BOOST_DEDUCED_TYPENAME bm_type::reference r = *bm.begin(); |
| 89 | r.right = 0.1; |
| 90 | BOOST_TEST( r == *bm.begin() ); |
| 91 | |
| 92 | BOOST_DEDUCED_TYPENAME bm_type::const_reference cr = *bm.begin(); |
| 93 | BOOST_TEST( cr == *bm.begin() ); |
| 94 | |
| 95 | BOOST_DEDUCED_TYPENAME bm_type::const_reference ccr = *cbm.begin(); |
| 96 | BOOST_TEST( ccr == *bm.begin() ); |
| 97 | |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | int main() |
| 102 | { |
| 103 | test_bimap_mutable< bimap< int, list_of<double> > >(); |
| 104 | test_bimap_mutable< bimap< int, vector_of<double> > >(); |
| 105 | test_bimap_mutable< bimap< int, unconstrained_set_of<double> > >(); |
| 106 | return boost::report_errors(); |
| 107 | } |
| 108 | |
| 109 |
