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/move/unique_ptr.hpp>
18 #include <boost/move/utility_core.hpp>
21 #include <boost/container/detail/iterator.hpp>
27 template< class T1, class T2>
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
36 template<class T1, class T2, class C1, class C2>
37 bool CheckEqualIt( const T1 &i1, const T2 &i2, const C1 &c1, const C2 &c2 )
39 bool c1end = i1 == c1.end();
40 bool c2end = i2 == c2.end();
48 return CheckEqual(*i1, *i2);
52 template< class Pair1, class Pair2>
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
59 return CheckEqual(pair1.first, pair2.first) && CheckEqual(pair1.second, pair2.second);
62 //Function to check if both containers are equal
65 bool CheckEqualContainers(const ContA &cont_a, const ContB &cont_b)
67 if(cont_a.size() != cont_b.size())
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()){
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()){
81 for(; itcont_a != itcont_a_end; ++itcont_a, ++itcont_b, ++i){
82 if(!CheckEqual(*itcont_a, *itcont_b))
88 template<class MyBoostCont
90 bool CheckEqualPairContainers(const MyBoostCont &boostcont, const MyStdCont &stdcont)
92 if(boostcont.size() != stdcont.size())
95 typedef typename MyBoostCont::key_type key_type;
96 typedef typename MyBoostCont::mapped_type mapped_type;
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)
105 mapped_type m(itstd->second);
106 if(itboost->second != m)
112 struct less_transparent
114 typedef void is_transparent;
116 template<class T, class U>
117 bool operator()(const T &t, const U &u) const
123 struct equal_transparent
125 typedef void is_transparent;
127 template<class T, class U>
128 bool operator()(const T &t, const U &u) const
137 typename boost::move_detail::add_rvalue_reference<T>::type operator()(T &t)
139 return boost::move(t);
146 const T & operator()(const T &t)
154 } //namespace container {
157 #include <boost/container/detail/config_end.hpp>
159 #endif //#ifndef BOOST_CONTAINER_TEST_CHECK_EQUAL_CONTAINER_HPP