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