1//////////////////////////////////////////////////////////////////////////////
2//
3// (C) Copyright Ion Gaztanaga 2006. Distributed under the Boost
4// Software License, Version 1.0. (See accompanying file
5// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6//
7// See http://www.boost.org/libs/container for documentation.
8//
9//////////////////////////////////////////////////////////////////////////////
10
11#ifndef BOOST_CONTAINER_TEST_CHECK_EQUAL_CONTAINER_HPP
12#define BOOST_CONTAINER_TEST_CHECK_EQUAL_CONTAINER_HPP
13
14#include <boost/container/detail/config_begin.hpp>
15#include <boost/container/detail/pair.hpp>
16#include <boost/container/detail/mpl.hpp>
17#include <boost/container/detail/is_pair.hpp>
18#include <boost/move/unique_ptr.hpp>
19#include <boost/move/utility_core.hpp>
20
21#include <cstddef>
22#include <boost/container/detail/iterator.hpp>
23
24namespace boost{
25namespace container {
26namespace test{
27
28template< class T1, class T2>
29bool CheckEqual( const T1 &t1, const T2 &t2
30 , typename boost::container::dtl::enable_if_c
31 <!boost::container::dtl::is_pair<T1>::value &&
32 !boost::container::dtl::is_pair<T2>::value
33 >::type* = 0)
34{ return t1 == t2; }
35
36
37template<class T1, class T2, class C1, class C2>
38bool CheckEqualIt( const T1 &i1, const T2 &i2, const C1 &c1, const C2 &c2 )
39{
40 bool c1end = i1 == c1.end();
41 bool c2end = i2 == c2.end();
42 if( c1end != c2end ){
43 return false;
44 }
45 else if(c1end){
46 return true;
47 }
48 else{
49 return CheckEqual(*i1, *i2);
50 }
51}
52
53template< class Pair1, class Pair2>
54bool CheckEqual( const Pair1 &pair1, const Pair2 &pair2
55 , typename boost::container::dtl::enable_if_c
56 <boost::container::dtl::is_pair<Pair1>::value &&
57 boost::container::dtl::is_pair<Pair2>::value
58 >::type* = 0)
59{
60 return CheckEqual(pair1.first, pair2.first) && CheckEqual(pair1.second, pair2.second);
61}
62
63//Function to check if both containers are equal
64template<class ContA
65 ,class ContB>
66bool CheckEqualContainers(const ContA &cont_a, const ContB &cont_b)
67{
68 if(cont_a.size() != cont_b.size())
69 return false;
70
71 typename ContA::const_iterator itcont_a(cont_a.begin()), itcont_a_end(cont_a.end());
72 typename ContB::const_iterator itcont_b(cont_b.begin()), itcont_b_end(cont_b.end());;
73 typename ContB::size_type dist = boost::container::iterator_udistance(itcont_a, itcont_a_end);
74 if(dist != cont_a.size()){
75 return false;
76 }
77 typename ContA::size_type dist2 = boost::container::iterator_udistance(itcont_b, itcont_b_end);
78 if(dist2 != cont_b.size()){
79 return false;
80 }
81 std::size_t i = 0;
82 for(; itcont_a != itcont_a_end; ++itcont_a, ++itcont_b, ++i){
83 if(!CheckEqual(*itcont_a, *itcont_b))
84 return false;
85 }
86 return true;
87}
88
89template<class MyBoostCont
90 ,class MyStdCont>
91bool CheckEqualPairContainers(const MyBoostCont &boostcont, const MyStdCont &stdcont)
92{
93 if(boostcont.size() != stdcont.size())
94 return false;
95
96 typedef typename MyBoostCont::key_type key_type;
97 typedef typename MyBoostCont::mapped_type mapped_type;
98
99 typename MyBoostCont::const_iterator itboost(boostcont.begin()), itboostend(boostcont.end());
100 typename MyStdCont::const_iterator itstd(stdcont.begin());
101 for(; itboost != itboostend; ++itboost, ++itstd){
102 key_type k(itstd->first);
103 if(itboost->first != k)
104 return false;
105
106 mapped_type m(itstd->second);
107 if(itboost->second != m)
108 return false;
109 }
110 return true;
111}
112
113struct less_transparent
114{
115 typedef void is_transparent;
116
117 template<class T, class U>
118 bool operator()(const T &t, const U &u) const
119 {
120 return t < u;
121 }
122};
123
124struct equal_transparent
125{
126 typedef void is_transparent;
127
128 template<class T, class U>
129 bool operator()(const T &t, const U &u) const
130 {
131 return t == u;
132 }
133};
134
135struct move_op
136{
137 template<class T>
138 typename boost::move_detail::add_rvalue_reference<T>::type operator()(T &t)
139 {
140 return boost::move(t);
141 }
142};
143
144struct const_ref_op
145{
146 template<class T>
147 const T & operator()(const T &t)
148 {
149 return t;
150 }
151
152};
153
154} //namespace test{
155} //namespace container {
156} //namespace boost{
157
158#include <boost/container/detail/config_end.hpp>
159
160#endif //#ifndef BOOST_CONTAINER_TEST_CHECK_EQUAL_CONTAINER_HPP
161

source code of boost/libs/container/test/check_equal_containers.hpp