• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // std
21 #include <string>
22 
23 #include <boost/core/lightweight_test.hpp>
24 
25 // Boost.MPL
26 #include <boost/mpl/assert.hpp>
27 #include <boost/type_traits/is_same.hpp>
28 
29 // Boost.Bimap
30 #include <boost/bimap/detail/test/check_metadata.hpp>
31 #include <boost/bimap/tags/tagged.hpp>
32 
33 // Boost.Bimap.Relation
34 #include <boost/bimap/relation/mutant_relation.hpp>
35 #include <boost/bimap/relation/member_at.hpp>
36 #include <boost/bimap/relation/support/get.hpp>
37 #include <boost/bimap/relation/support/pair_by.hpp>
38 #include <boost/bimap/relation/support/pair_type_by.hpp>
39 #include <boost/bimap/relation/support/value_type_of.hpp>
40 #include <boost/bimap/relation/support/member_with_tag.hpp>
41 #include <boost/bimap/relation/support/is_tag_of_member_at.hpp>
42 
43 // Bimap Test Utilities
44 #include "test_relation.hpp"
45 
BOOST_BIMAP_TEST_STATIC_FUNCTION(untagged_static_test)46 BOOST_BIMAP_TEST_STATIC_FUNCTION( untagged_static_test )
47 {
48     using namespace boost::bimaps::relation::member_at;
49     using namespace boost::bimaps::relation;
50     using namespace boost::bimaps::tags;
51 
52     struct left_data  {};
53     struct right_data {};
54 
55     typedef mutant_relation< left_data, right_data > rel;
56 
57     BOOST_BIMAP_CHECK_METADATA(rel,left_value_type ,left_data);
58     BOOST_BIMAP_CHECK_METADATA(rel,right_value_type,right_data);
59 
60     BOOST_BIMAP_CHECK_METADATA(rel,left_tag ,left );
61     BOOST_BIMAP_CHECK_METADATA(rel,right_tag,right);
62 
63     typedef tagged<left_data ,left > desired_tagged_left_type;
64     BOOST_BIMAP_CHECK_METADATA(rel,tagged_left_type,desired_tagged_left_type);
65 
66     typedef tagged<right_data,right> desired_tagged_right_type;
67     BOOST_BIMAP_CHECK_METADATA(rel,tagged_right_type,desired_tagged_right_type);
68 
69 }
70 
BOOST_BIMAP_TEST_STATIC_FUNCTION(tagged_static_test)71 BOOST_BIMAP_TEST_STATIC_FUNCTION( tagged_static_test)
72 {
73     using namespace boost::bimaps::relation::member_at;
74     using namespace boost::bimaps::relation;
75     using namespace boost::bimaps::tags;
76 
77     struct left_data  {};
78     struct right_data {};
79 
80     struct left_tag   {};
81     struct right_tag  {};
82 
83     typedef mutant_relation<
84         tagged<left_data,left_tag>, tagged<right_data,right_tag> > rel;
85 
86     BOOST_BIMAP_CHECK_METADATA(rel,left_value_type ,left_data);
87     BOOST_BIMAP_CHECK_METADATA(rel,right_value_type,right_data);
88 
89     BOOST_BIMAP_CHECK_METADATA(rel,left_tag ,left_tag  );
90     BOOST_BIMAP_CHECK_METADATA(rel,right_tag,right_tag );
91 
92     typedef tagged<left_data ,left_tag > desired_tagged_left_type;
93     BOOST_BIMAP_CHECK_METADATA(rel,tagged_left_type,desired_tagged_left_type);
94 
95     typedef tagged<right_data,right_tag> desired_tagged_right_type;
96     BOOST_BIMAP_CHECK_METADATA(rel,tagged_right_type,desired_tagged_right_type);
97 }
98 
99 struct mutant_relation_builder
100 {
101     template< class LeftType, class RightType >
102     struct build
103     {
104         typedef boost::bimaps::relation::
105             mutant_relation<LeftType,RightType,::boost::mpl::na,true> type;
106     };
107 };
108 
109 // Complex classes
110 
111 class cc1
112 {
113     public:
cc1(int s=0)114     cc1(int s = 0) : a(s+100), b(s+101) {}
115     static int sd;
116     int a;
117     const int b;
118 };
119 
operator ==(const cc1 & da,const cc1 & db)120 bool operator==(const cc1 & da, const cc1 & db)
121 {
122     return da.a == db.a && da.b == db.b;
123 }
124 
125 int cc1::sd = 102;
126 
127 class cc2_base
128 {
129     public:
cc2_base(int s)130     cc2_base(int s) : a(s+200) {}
131     int a;
132 };
133 
134 class cc2 : public cc2_base
135 {
136     public:
cc2(int s=0)137     cc2(int s = 0) : cc2_base(s), b(s+201) {}
138     int b;
139 };
140 
operator ==(const cc2 & da,const cc2 & db)141 bool operator==(const cc2 & da, const cc2 & db)
142 {
143     return da.a == db.a && da.b == db.b;
144 }
145 
146 class cc3_base
147 {
148     public:
cc3_base(int s=0)149     cc3_base(int s = 0) : a(s+300) {}
150     const int a;
151 };
152 
153 class cc3 : virtual public cc3_base
154 {
155    public:
cc3(int s=0)156    cc3(int s = 0) : cc3_base(s), b(s+301) {}
157    int b;
158 };
159 
operator ==(const cc3 & da,const cc3 & db)160 bool operator==(const cc3 & da, const cc3 & db)
161 {
162     return da.a == db.a && da.b == db.b;
163 }
164 
165 class cc4_base
166 {
167     public:
cc4_base(int s)168     cc4_base(int s) : a(s+400) {}
~cc4_base()169     virtual ~cc4_base() {}
170     const int a;
171 };
172 
173 class cc4 : public cc4_base
174 {
175    public:
cc4(int s=0)176    cc4(int s = 0) : cc4_base(s), b(s+401) {}
177    int b;
178 };
179 
operator ==(const cc4 & da,const cc4 & db)180 bool operator==(const cc4 & da, const cc4 & db)
181 {
182     return da.a == db.a && da.b == db.b;
183 }
184 
185 class cc5 : public cc1, public cc3, public cc4
186 {
187     public:
cc5(int s=0)188     cc5(int s = 0) : cc1(s), cc3(s), cc4(s) {}
189 };
190 
operator ==(const cc5 & da,const cc5 & db)191 bool operator==(const cc5 & da, const cc5 & db)
192 {
193     return da.cc1::a == db.cc1::a && da.cc1::b == db.cc1::b &&
194            da.cc3::a == db.cc3::a && da.cc3::b == db.cc3::b &&
195            da.cc4::a == db.cc4::a && da.cc4::b == db.cc4::b;
196 }
197 
198 class cc6
199 {
200     public:
cc6(int s=0)201     cc6(int s = 0) : a(s+600), b(a) {}
202     int a;
203     int & b;
204 };
205 
operator ==(const cc6 & da,const cc6 & db)206 bool operator==(const cc6 & da, const cc6 & db)
207 {
208     return da.a == db.a && da.b == db.b;
209 }
210 
test_mutant_relation()211 void test_mutant_relation()
212 {
213     test_relation< mutant_relation_builder, char  , double >( 'l', 2.5 );
214     test_relation< mutant_relation_builder, double, char   >( 2.5, 'r' );
215 
216     test_relation<mutant_relation_builder, int   , int    >(  1 ,   2 );
217 
218     test_relation<mutant_relation_builder, std::string, int* >("left value",0);
219 
220     test_relation<mutant_relation_builder, cc1, cc2>(0,0);
221     test_relation<mutant_relation_builder, cc2, cc3>(0,0);
222     test_relation<mutant_relation_builder, cc3, cc4>(0,0);
223     test_relation<mutant_relation_builder, cc4, cc5>(0,0);
224 }
225 
main()226 int main()
227 {
228 
229     // Test metadata correctness with untagged relation version
230     BOOST_BIMAP_CALL_TEST_STATIC_FUNCTION( tagged_static_test   );
231 
232     // Test metadata correctness with tagged relation version
233     BOOST_BIMAP_CALL_TEST_STATIC_FUNCTION( untagged_static_test );
234 
235     // Test basic
236     test_mutant_relation();
237 
238     return boost::report_errors();
239 }
240 
241