check_equal_containers.hpp 4.3 KB

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