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 | // std |
23 | #include <utility> |
24 | #include <cstddef> |
25 | |
26 | // Boost.Static_assert |
27 | #include <boost/static_assert.hpp> |
28 | |
29 | // Boost.Bimap |
30 | #include <boost/bimap/detail/test/check_metadata.hpp> |
31 | |
32 | #include <boost/bimap/relation/structured_pair.hpp> |
33 | |
34 | |
35 | BOOST_BIMAP_TEST_STATIC_FUNCTION( static_metadata_test ) |
36 | { |
37 | using namespace boost::bimaps::relation; |
38 | |
39 | struct data_a { char data; }; |
40 | struct data_b { double data; }; |
41 | |
42 | typedef structured_pair |
43 | < |
44 | data_a, |
45 | data_b, |
46 | normal_layout |
47 | |
48 | > sp_ab; |
49 | |
50 | typedef structured_pair |
51 | < |
52 | data_b, |
53 | data_a, |
54 | mirror_layout |
55 | |
56 | > sp_ba; |
57 | |
58 | BOOST_BIMAP_CHECK_METADATA(sp_ab, first_type , data_a); |
59 | BOOST_BIMAP_CHECK_METADATA(sp_ab, second_type, data_b); |
60 | |
61 | BOOST_BIMAP_CHECK_METADATA(sp_ba, first_type , data_b); |
62 | BOOST_BIMAP_CHECK_METADATA(sp_ba, second_type, data_a); |
63 | |
64 | } |
65 | |
66 | |
67 | void test_basic() |
68 | { |
69 | |
70 | using namespace boost::bimaps::relation; |
71 | |
72 | // Instantiate two pairs and test the storage alignmentDataData |
73 | |
74 | typedef structured_pair< short, double, normal_layout > pair_type; |
75 | typedef structured_pair< double, short, mirror_layout > mirror_type; |
76 | |
77 | pair_type pa( 2, 3.1416 ); |
78 | mirror_type pb( 3.1416, 2 ); |
79 | |
80 | BOOST_TEST( pa.first == pb.second ); |
81 | BOOST_TEST( pa.second == pb.first ); |
82 | |
83 | } |
84 | |
85 | |
86 | int main() |
87 | { |
88 | |
89 | BOOST_BIMAP_CALL_TEST_STATIC_FUNCTION( static_are_storage_compatible_test ); |
90 | |
91 | BOOST_BIMAP_CALL_TEST_STATIC_FUNCTION( static_metadata_test ); |
92 | |
93 | test_basic(); |
94 | |
95 | return boost::report_errors(); |
96 | } |
97 | |
98 | |