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.MPL 23 #include <boost/mpl/list.hpp> 24 #include <boost/type_traits/is_same.hpp> 25 26 // Boost.Bimap 27 #include <boost/bimap/relation/detail/mutant.hpp> 28 29 using namespace boost::bimaps::relation::detail; 30 31 // The mutant idiom is standard if only POD types are used. 32 33 typedef double type_a; 34 typedef int type_b; 35 36 const type_a value_a = 1.4; 37 const type_b value_b = 3; 38 39 struct Data 40 { 41 type_a a; 42 type_b b; 43 }; 44 45 struct StdPairView 46 { 47 typedef type_a first_type; 48 typedef type_b second_type; 49 type_a first; 50 type_b second; 51 }; 52 53 struct ReverseStdPairView 54 { 55 typedef type_a second_type; 56 typedef type_b first_type; 57 type_a second; 58 type_b first; 59 }; 60 61 62 struct MutantData 63 { 64 typedef boost::mpl::list< StdPairView, ReverseStdPairView > mutant_views; 65 MutantDataMutantData66 MutantData(type_a ap, type_b bp) : a(ap), b(bp) {} 67 type_a a; 68 type_b b; 69 }; 70 71 test_mutant_basic()72void test_mutant_basic() 73 { 74 75 // mutant test 76 { 77 MutantData m(value_a,value_b); 78 79 BOOST_TEST( sizeof( MutantData ) == sizeof( StdPairView ) ); 80 81 BOOST_TEST( mutate<StdPairView>(m).first == value_a ); 82 BOOST_TEST( mutate<StdPairView>(m).second == value_b ); 83 BOOST_TEST( mutate<ReverseStdPairView>(m).first == value_b ); 84 BOOST_TEST( mutate<ReverseStdPairView>(m).second == value_a ); 85 86 ReverseStdPairView & rpair = mutate<ReverseStdPairView>(m); 87 rpair.first = value_b; 88 rpair.second = value_a; 89 90 BOOST_TEST( mutate<StdPairView>(m).first == value_a ); 91 BOOST_TEST( mutate<StdPairView>(m).second == value_b ); 92 93 BOOST_TEST( &mutate<StdPairView>(m).first == &m.a ); 94 BOOST_TEST( &mutate<StdPairView>(m).second == &m.b ); 95 } 96 } 97 main()98int main() 99 { 100 test_mutant_basic(); 101 return boost::report_errors(); 102 } 103