1 //////////////////////////////////////////////////////////////////////////////
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)
7 // See http://www.boost.org/libs/container for documentation.
9 //////////////////////////////////////////////////////////////////////////////
11 #ifndef BOOST_CONTAINER_TEST_CHECK_EQUAL_CONTAINER_HPP
12 #define BOOST_CONTAINER_TEST_CHECK_EQUAL_CONTAINER_HPP
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>
22 #include <boost/container/detail/iterator.hpp>
28 template< class T1, class T2>
29 bool 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
37 template<class T1, class T2, class C1, class C2>
38 bool CheckEqualIt( const T1 &i1, const T2 &i2, const C1 &c1, const C2 &c2 )
40 bool c1end = i1 == c1.end();
41 bool c2end = i2 == c2.end();
49 return CheckEqual(*i1, *i2);
53 template< class Pair1, class Pair2>
54 bool 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
60 return CheckEqual(pair1.first, pair2.first) && CheckEqual(pair1.second, pair2.second);
63 //Function to check if both containers are equal
66 bool CheckEqualContainers(const ContA &cont_a, const ContB &cont_b)
68 if(cont_a.size() != cont_b.size())
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()){
77 typename ContA::size_type dist2 = boost::container::iterator_udistance(itcont_b, itcont_b_end);
78 if(dist2 != cont_b.size()){
82 for(; itcont_a != itcont_a_end; ++itcont_a, ++itcont_b, ++i){
83 if(!CheckEqual(*itcont_a, *itcont_b))
89 template<class MyBoostCont
91 bool CheckEqualPairContainers(const MyBoostCont &boostcont, const MyStdCont &stdcont)
93 if(boostcont.size() != stdcont.size())
96 typedef typename MyBoostCont::key_type key_type;
97 typedef typename MyBoostCont::mapped_type mapped_type;
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)
106 mapped_type m(itstd->second);
107 if(itboost->second != m)
113 struct less_transparent
115 typedef void is_transparent;
117 template<class T, class U>
118 bool operator()(const T &t, const U &u) const
124 struct equal_transparent
126 typedef void is_transparent;
128 template<class T, class U>
129 bool operator()(const T &t, const U &u) const
138 typename boost::move_detail::add_rvalue_reference<T>::type operator()(T &t)
140 return boost::move(t);
147 const T & operator()(const T &t)
155 } //namespace container {
158 #include <boost/container/detail/config_end.hpp>
160 #endif //#ifndef BOOST_CONTAINER_TEST_CHECK_EQUAL_CONTAINER_HPP