3 // Copyright (c) 2006-2007 Matias Capeletto
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)
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
18 #include <boost/config.hpp>
24 #include <boost/test/minimal.hpp>
27 #include <boost/mpl/assert.hpp>
28 #include <boost/type_traits/is_same.hpp>
31 #include <boost/bimap/detail/test/check_metadata.hpp>
32 #include <boost/bimap/tags/tagged.hpp>
34 // Boost.Bimap.Relation
35 #include <boost/bimap/relation/mutant_relation.hpp>
36 #include <boost/bimap/relation/member_at.hpp>
37 #include <boost/bimap/relation/support/get.hpp>
38 #include <boost/bimap/relation/support/pair_by.hpp>
39 #include <boost/bimap/relation/support/pair_type_by.hpp>
40 #include <boost/bimap/relation/support/value_type_of.hpp>
41 #include <boost/bimap/relation/support/member_with_tag.hpp>
42 #include <boost/bimap/relation/support/is_tag_of_member_at.hpp>
44 // Bimap Test Utilities
45 #include "test_relation.hpp"
47 BOOST_BIMAP_TEST_STATIC_FUNCTION( untagged_static_test
)
49 using namespace boost::bimaps::relation::member_at
;
50 using namespace boost::bimaps::relation
;
51 using namespace boost::bimaps::tags
;
56 typedef mutant_relation
< left_data
, right_data
> rel
;
58 BOOST_BIMAP_CHECK_METADATA(rel
,left_value_type
,left_data
);
59 BOOST_BIMAP_CHECK_METADATA(rel
,right_value_type
,right_data
);
61 BOOST_BIMAP_CHECK_METADATA(rel
,left_tag
,left
);
62 BOOST_BIMAP_CHECK_METADATA(rel
,right_tag
,right
);
64 typedef tagged
<left_data
,left
> desired_tagged_left_type
;
65 BOOST_BIMAP_CHECK_METADATA(rel
,tagged_left_type
,desired_tagged_left_type
);
67 typedef tagged
<right_data
,right
> desired_tagged_right_type
;
68 BOOST_BIMAP_CHECK_METADATA(rel
,tagged_right_type
,desired_tagged_right_type
);
72 BOOST_BIMAP_TEST_STATIC_FUNCTION( tagged_static_test
)
74 using namespace boost::bimaps::relation::member_at
;
75 using namespace boost::bimaps::relation
;
76 using namespace boost::bimaps::tags
;
84 typedef mutant_relation
<
85 tagged
<left_data
,left_tag
>, tagged
<right_data
,right_tag
> > rel
;
87 BOOST_BIMAP_CHECK_METADATA(rel
,left_value_type
,left_data
);
88 BOOST_BIMAP_CHECK_METADATA(rel
,right_value_type
,right_data
);
90 BOOST_BIMAP_CHECK_METADATA(rel
,left_tag
,left_tag
);
91 BOOST_BIMAP_CHECK_METADATA(rel
,right_tag
,right_tag
);
93 typedef tagged
<left_data
,left_tag
> desired_tagged_left_type
;
94 BOOST_BIMAP_CHECK_METADATA(rel
,tagged_left_type
,desired_tagged_left_type
);
96 typedef tagged
<right_data
,right_tag
> desired_tagged_right_type
;
97 BOOST_BIMAP_CHECK_METADATA(rel
,tagged_right_type
,desired_tagged_right_type
);
100 struct mutant_relation_builder
102 template< class LeftType
, class RightType
>
105 typedef boost::bimaps::relation::
106 mutant_relation
<LeftType
,RightType
,::boost::mpl::na
,true> type
;
115 cc1(int s
= 0) : a(s
+100), b(s
+101) {}
121 bool operator==(const cc1
& da
, const cc1
& db
)
123 return da
.a
== db
.a
&& da
.b
== db
.b
;
131 cc2_base(int s
) : a(s
+200) {}
135 class cc2
: public cc2_base
138 cc2(int s
= 0) : cc2_base(s
), b(s
+201) {}
142 bool operator==(const cc2
& da
, const cc2
& db
)
144 return da
.a
== db
.a
&& da
.b
== db
.b
;
150 cc3_base(int s
= 0) : a(s
+300) {}
154 class cc3
: virtual public cc3_base
157 cc3(int s
= 0) : cc3_base(s
), b(s
+301) {}
161 bool operator==(const cc3
& da
, const cc3
& db
)
163 return da
.a
== db
.a
&& da
.b
== db
.b
;
169 cc4_base(int s
) : a(s
+400) {}
170 virtual ~cc4_base() {}
174 class cc4
: public cc4_base
177 cc4(int s
= 0) : cc4_base(s
), b(s
+401) {}
181 bool operator==(const cc4
& da
, const cc4
& db
)
183 return da
.a
== db
.a
&& da
.b
== db
.b
;
186 class cc5
: public cc1
, public cc3
, public cc4
189 cc5(int s
= 0) : cc1(s
), cc3(s
), cc4(s
) {}
192 bool operator==(const cc5
& da
, const cc5
& db
)
194 return da
.cc1::a
== db
.cc1::a
&& da
.cc1::b
== db
.cc1::b
&&
195 da
.cc3::a
== db
.cc3::a
&& da
.cc3::b
== db
.cc3::b
&&
196 da
.cc4::a
== db
.cc4::a
&& da
.cc4::b
== db
.cc4::b
;
202 cc6(int s
= 0) : a(s
+600), b(a
) {}
207 bool operator==(const cc6
& da
, const cc6
& db
)
209 return da
.a
== db
.a
&& da
.b
== db
.b
;
212 void test_mutant_relation()
214 test_relation
< mutant_relation_builder
, char , double >( 'l', 2.5 );
215 test_relation
< mutant_relation_builder
, double, char >( 2.5, 'r' );
217 test_relation
<mutant_relation_builder
, int , int >( 1 , 2 );
219 test_relation
<mutant_relation_builder
, std::string
, int* >("left value",0);
221 test_relation
<mutant_relation_builder
, cc1
, cc2
>(0,0);
222 test_relation
<mutant_relation_builder
, cc2
, cc3
>(0,0);
223 test_relation
<mutant_relation_builder
, cc3
, cc4
>(0,0);
224 test_relation
<mutant_relation_builder
, cc4
, cc5
>(0,0);
227 int test_main( int, char* [] )
230 // Test metadata correctness with untagged relation version
231 BOOST_BIMAP_CALL_TEST_STATIC_FUNCTION( tagged_static_test
);
233 // Test metadata correctness with tagged relation version
234 BOOST_BIMAP_CALL_TEST_STATIC_FUNCTION( untagged_static_test
);
237 test_mutant_relation();