]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/bimap/test/test_relation.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / bimap / test / test_relation.hpp
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 #ifndef BOOST_BIMAP_TEST_TEST_RELATION_HPP
10 #define BOOST_BIMAP_TEST_TEST_RELATION_HPP
11
12 #if defined(_MSC_VER)
13 #pragma once
14 #endif
15
16 #include <boost/config.hpp>
17
18 // Boost.Test
19 #include <boost/test/minimal.hpp>
20
21 // Boost.MPL
22 #include <boost/mpl/assert.hpp>
23 #include <boost/type_traits/is_same.hpp>
24
25 // Boost.Bimap
26 #include <boost/bimap/detail/test/check_metadata.hpp>
27 #include <boost/bimap/tags/tagged.hpp>
28
29 // Boost.Bimap.Relation
30 #include <boost/bimap/relation/member_at.hpp>
31 #include <boost/bimap/relation/support/get.hpp>
32 #include <boost/bimap/relation/support/pair_by.hpp>
33 #include <boost/bimap/relation/support/pair_type_by.hpp>
34 #include <boost/bimap/relation/support/value_type_of.hpp>
35 #include <boost/bimap/relation/support/member_with_tag.hpp>
36 #include <boost/bimap/relation/support/is_tag_of_member_at.hpp>
37
38
39
40 template< class Relation >
41 void test_relation_with_default_tags(Relation & rel,
42 const typename Relation::left_value_type & lv,
43 const typename Relation::right_value_type & rv)
44 {
45
46 using namespace boost::bimaps::relation::support;
47 using namespace boost::bimaps::relation;
48 using namespace boost::bimaps::tags;
49
50 // It must work with normal tags
51
52 BOOST_CHECK( pair_by<member_at::left >(rel).first == lv );
53 BOOST_CHECK( pair_by<member_at::left >(rel).second == rv );
54
55 BOOST_CHECK( pair_by<member_at::right>(rel).first == rv );
56 BOOST_CHECK( pair_by<member_at::right>(rel).second == lv );
57
58 BOOST_CHECK( get<member_at::left >(rel) == rel.left );
59 BOOST_CHECK( get<member_at::right>(rel) == rel.right );
60
61 BOOST_CHECK(
62 get<member_at::left >(pair_by<member_at::left >(rel)) == rel.left
63 );
64
65 BOOST_CHECK(
66 get<member_at::right>(pair_by<member_at::left >(rel)) == rel.right
67 );
68
69 BOOST_CHECK(
70 get<member_at::left >(pair_by<member_at::right>(rel)) == rel.left
71 );
72
73 BOOST_CHECK(
74 get<member_at::right>(pair_by<member_at::right>(rel)) == rel.right
75 );
76
77 }
78
79 template< class Relation, class LeftTag, class RightTag >
80 void test_relation_with_user_tags(Relation & rel,
81 const typename Relation::left_value_type & lv,
82 const typename Relation::right_value_type & rv)
83 {
84
85 using namespace boost::bimaps::relation::support;
86 using namespace boost::bimaps::relation;
87 using namespace boost::bimaps::tags;
88
89 // And with users ones
90
91 BOOST_CHECK( pair_by<LeftTag >(rel).first == lv );
92 BOOST_CHECK( pair_by<LeftTag >(rel).second == rv );
93
94 BOOST_CHECK( pair_by<RightTag>(rel).first == rv );
95 BOOST_CHECK( pair_by<RightTag>(rel).second == lv );
96
97 BOOST_CHECK( get<LeftTag >(rel) == rel.left );
98 BOOST_CHECK( get<RightTag>(rel) == rel.right );
99
100 BOOST_CHECK( get<LeftTag >(pair_by<LeftTag >(rel)) == rel.left );
101 BOOST_CHECK( get<RightTag>(pair_by<LeftTag >(rel)) == rel.right );
102
103 BOOST_CHECK( get<LeftTag >(pair_by<RightTag>(rel)) == rel.left );
104 BOOST_CHECK( get<RightTag>(pair_by<RightTag>(rel)) == rel.right );
105
106 //----------------------------------------------------------------
107
108 BOOST_CHECK( rel.template get<LeftTag >() == rel.left );
109 BOOST_CHECK( rel.template get<RightTag>() == rel.right );
110
111 BOOST_CHECK( pair_by<LeftTag >(rel).template get<LeftTag >()== rel.left );
112 BOOST_CHECK( pair_by<LeftTag >(rel).template get<RightTag>()== rel.right);
113
114 BOOST_CHECK( pair_by<RightTag>(rel).template get<LeftTag >()== rel.left );
115 BOOST_CHECK( pair_by<RightTag>(rel).template get<RightTag>()== rel.right);
116 }
117
118 struct left_user_tag {};
119 struct right_user_tag {};
120
121 template< class RelationBuilder, class LeftData, class RightData >
122 void test_relation(const LeftData & lv, const RightData & rv)
123 {
124 using namespace boost::bimaps::relation::support;
125 using namespace boost::bimaps::relation;
126 using boost::bimaps::tags::tagged;
127
128 // Untagged test
129 {
130 typedef typename RelationBuilder::template build
131 <
132 LeftData,
133 RightData
134
135 >::type rel_type;
136
137 rel_type rel( lv, rv );
138
139 test_relation_with_default_tags( rel, lv, rv);
140 }
141
142 // Tagged test
143 {
144 typedef typename RelationBuilder::template build
145 <
146 tagged<LeftData , left_user_tag >,
147 tagged<RightData, right_user_tag >
148
149 >::type rel_type;
150
151 rel_type rel( lv, rv );
152
153 test_relation_with_default_tags(rel, lv, rv );
154 test_relation_with_user_tags
155 <
156 rel_type,
157 left_user_tag,right_user_tag
158
159 >(rel,lv,rv);
160 }
161
162 // Default Constructor, Constructor from views and some operators
163 {
164 /*
165 typedef typename RelationBuilder::template build
166 <
167 tagged<LeftData , left_user_tag >,
168 tagged<RightData, right_user_tag >
169
170 >::type rel_type;
171
172 typedef typename pair_type_by< left_user_tag,rel_type>::type left_pair;
173 typedef typename pair_type_by<right_user_tag,rel_type>::type right_pair;
174
175 rel_type rel_from_left ( left_pair(lv,rv) );
176 rel_type rel_from_right( right_pair(rv,lv) );
177
178 BOOST_CHECK( rel_from_left == rel_from_right );
179 BOOST_CHECK( rel_from_left == rel_type(lv,rv) );
180
181 rel_type rel;
182
183 rel = rel_from_left;
184
185 BOOST_CHECK( rel == rel_from_left );
186 */
187 }
188
189 }
190
191 #endif // BOOST_BIMAP_TEST_TEST_RELATION_HPP