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