• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/move/unique_ptr.hpp>
18 #include <boost/move/utility_core.hpp>
19 
20 #include <cstddef>
21 #include <boost/container/detail/iterator.hpp>
22 
23 namespace boost{
24 namespace container {
25 namespace test{
26 
27 template< class T1, class T2>
CheckEqual(const T1 & t1,const T2 & t2,typename boost::container::dtl::enable_if_c<!boost::container::dtl::is_pair<T1>::value &&!boost::container::dtl::is_pair<T2>::value>::type * =0)28 bool CheckEqual( const T1 &t1, const T2 &t2
29                , typename boost::container::dtl::enable_if_c
30                   <!boost::container::dtl::is_pair<T1>::value &&
31                    !boost::container::dtl::is_pair<T2>::value
32                   >::type* = 0)
33 {  return t1 == t2;  }
34 
35 
36 template<class T1, class T2, class C1, class C2>
CheckEqualIt(const T1 & i1,const T2 & i2,const C1 & c1,const C2 & c2)37 bool CheckEqualIt( const T1 &i1, const T2 &i2, const C1 &c1, const C2 &c2 )
38 {
39    bool c1end = i1 == c1.end();
40    bool c2end = i2 == c2.end();
41    if( c1end != c2end ){
42       return false;
43    }
44    else if(c1end){
45       return true;
46    }
47    else{
48       return CheckEqual(*i1, *i2);
49    }
50 }
51 
52 template< class Pair1, class Pair2>
CheckEqual(const Pair1 & pair1,const Pair2 & pair2,typename boost::container::dtl::enable_if_c<boost::container::dtl::is_pair<Pair1>::value && boost::container::dtl::is_pair<Pair2>::value>::type * =0)53 bool CheckEqual( const Pair1 &pair1, const Pair2 &pair2
54                , typename boost::container::dtl::enable_if_c
55                   <boost::container::dtl::is_pair<Pair1>::value &&
56                    boost::container::dtl::is_pair<Pair2>::value
57                   >::type* = 0)
58 {
59    return CheckEqual(pair1.first, pair2.first) && CheckEqual(pair1.second, pair2.second);
60 }
61 
62 //Function to check if both containers are equal
63 template<class ContA
64         ,class ContB>
CheckEqualContainers(const ContA & cont_a,const ContB & cont_b)65 bool CheckEqualContainers(const ContA &cont_a, const ContB &cont_b)
66 {
67    if(cont_a.size() != cont_b.size())
68       return false;
69 
70    typename ContA::const_iterator itcont_a(cont_a.begin()), itcont_a_end(cont_a.end());
71    typename ContB::const_iterator itcont_b(cont_b.begin()), itcont_b_end(cont_b.end());;
72    typename ContB::size_type dist = (typename ContB::size_type)boost::container::iterator_distance(itcont_a, itcont_a_end);
73    if(dist != cont_a.size()){
74       return false;
75    }
76    typename ContA::size_type dist2 = (typename ContA::size_type)boost::container::iterator_distance(itcont_b, itcont_b_end);
77    if(dist2 != cont_b.size()){
78       return false;
79    }
80    std::size_t i = 0;
81    for(; itcont_a != itcont_a_end; ++itcont_a, ++itcont_b, ++i){
82       if(!CheckEqual(*itcont_a, *itcont_b))
83          return false;
84    }
85    return true;
86 }
87 
88 template<class MyBoostCont
89         ,class MyStdCont>
CheckEqualPairContainers(const MyBoostCont & boostcont,const MyStdCont & stdcont)90 bool CheckEqualPairContainers(const MyBoostCont &boostcont, const MyStdCont &stdcont)
91 {
92    if(boostcont.size() != stdcont.size())
93       return false;
94 
95    typedef typename MyBoostCont::key_type      key_type;
96    typedef typename MyBoostCont::mapped_type   mapped_type;
97 
98    typename MyBoostCont::const_iterator itboost(boostcont.begin()), itboostend(boostcont.end());
99    typename MyStdCont::const_iterator itstd(stdcont.begin());
100    for(; itboost != itboostend; ++itboost, ++itstd){
101       key_type k(itstd->first);
102       if(itboost->first != k)
103          return false;
104 
105       mapped_type m(itstd->second);
106       if(itboost->second != m)
107          return false;
108    }
109    return true;
110 }
111 
112 struct less_transparent
113 {
114    typedef void is_transparent;
115 
116    template<class T, class U>
operator ()boost::container::test::less_transparent117    bool operator()(const T &t, const U &u) const
118    {
119       return t < u;
120    }
121 };
122 
123 struct equal_transparent
124 {
125    typedef void is_transparent;
126 
127    template<class T, class U>
operator ()boost::container::test::equal_transparent128    bool operator()(const T &t, const U &u) const
129    {
130       return t == u;
131    }
132 };
133 
134 struct move_op
135 {
136    template<class T>
operator ()boost::container::test::move_op137    typename boost::move_detail::add_rvalue_reference<T>::type operator()(T &t)
138    {
139       return boost::move(t);
140    }
141 };
142 
143 struct const_ref_op
144 {
145    template<class T>
operator ()boost::container::test::const_ref_op146    const T & operator()(const T &t)
147    {
148       return t;
149    }
150 
151 };
152 
153 }  //namespace test{
154 }  //namespace container {
155 }  //namespace boost{
156 
157 #include <boost/container/detail/config_end.hpp>
158 
159 #endif //#ifndef BOOST_CONTAINER_TEST_CHECK_EQUAL_CONTAINER_HPP
160