map_algo.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*-----------------------------------------------------------------------------+
  2. Copyright (c) 2007-2010: Joachim Faulhaber
  3. +------------------------------------------------------------------------------+
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENCE.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. +-----------------------------------------------------------------------------*/
  8. #ifndef BOOST_ICL_MAPALGO_HPP_JOFA_080225
  9. #define BOOST_ICL_MAPALGO_HPP_JOFA_080225
  10. #include <boost/mpl/and.hpp>
  11. #include <boost/mpl/or.hpp>
  12. #include <boost/mpl/not.hpp>
  13. #include <boost/icl/detail/notate.hpp>
  14. #include <boost/icl/detail/set_algo.hpp>
  15. #ifdef BOOST_MSVC
  16. #pragma warning(push)
  17. #pragma warning(disable:4127) // conditional expression is constant
  18. #endif
  19. namespace boost{namespace icl
  20. {
  21. namespace Map
  22. {
  23. template <class ObjectT, class CoObjectT>
  24. bool intersects(const ObjectT& left, const CoObjectT& right)
  25. {
  26. typedef typename CoObjectT::const_iterator co_iterator;
  27. co_iterator right_common_lower_, right_common_upper_;
  28. if(!Set::common_range(right_common_lower_, right_common_upper_, right, left))
  29. return false;
  30. co_iterator right_ = right_common_lower_;
  31. while(right_ != right_common_upper_)
  32. if(!(left.find(key_value<CoObjectT>(right_++))==left.end()))
  33. return true;
  34. return false;
  35. }
  36. template<class MapT>
  37. typename MapT::const_iterator next_proton(typename MapT::const_iterator& iter_, const MapT& object)
  38. {
  39. while( iter_ != object.end()
  40. && (*iter_).second == identity_element<typename MapT::codomain_type>::value())
  41. ++iter_;
  42. return iter_;
  43. }
  44. /** Function template <tt>lexicographical_equal</tt> implements
  45. lexicographical equality except for identity_elementic content values. */
  46. template<class MapT>
  47. bool lexicographical_distinct_equal(const MapT& left, const MapT& right)
  48. {
  49. if(&left == &right)
  50. return true;
  51. typename MapT::const_iterator left_ = left.begin();
  52. typename MapT::const_iterator right_ = right.begin();
  53. left_ = next_proton(left_, left);
  54. right_ = next_proton(right_, right);
  55. while(left_ != left.end() && right_ != right.end())
  56. {
  57. if(!(left_->first == right_->first && left_->second == right_->second))
  58. return false;
  59. ++left_;
  60. ++right_;
  61. left_ = next_proton(left_, left);
  62. right_ = next_proton(right_, right);
  63. }
  64. return left_ == left.end() && right_ == right.end();
  65. }
  66. } // namespace Map
  67. }} // namespace boost icl
  68. #ifdef BOOST_MSVC
  69. #pragma warning(pop)
  70. #endif
  71. #endif