lexicographic.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* Boost interval/compare/lexicographic.hpp template implementation file
  2. *
  3. * Copyright 2002-2003 Guillaume Melquiond
  4. *
  5. * Distributed under the Boost Software License, Version 1.0.
  6. * (See accompanying file LICENSE_1_0.txt or
  7. * copy at http://www.boost.org/LICENSE_1_0.txt)
  8. */
  9. #ifndef BOOST_NUMERIC_INTERVAL_COMPARE_LEXICOGRAPHIC_HPP
  10. #define BOOST_NUMERIC_INTERVAL_COMPARE_LEXICOGRAPHIC_HPP
  11. #include <boost/numeric/interval/detail/interval_prototype.hpp>
  12. #include <boost/numeric/interval/detail/test_input.hpp>
  13. namespace boost {
  14. namespace numeric {
  15. namespace interval_lib {
  16. namespace compare {
  17. namespace lexicographic {
  18. template<class T, class Policies1, class Policies2> inline
  19. bool operator<(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
  20. {
  21. if (detail::test_input(x, y)) throw comparison_error();
  22. const T& xl = x.lower();
  23. const T& yl = y.lower();
  24. return xl < yl || (xl == yl && x.upper() < y.upper());
  25. }
  26. template<class T, class Policies> inline
  27. bool operator<(const interval<T, Policies>& x, const T& y)
  28. {
  29. if (detail::test_input(x, y)) throw comparison_error();
  30. return x.lower() < y;
  31. }
  32. template<class T, class Policies1, class Policies2> inline
  33. bool operator<=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
  34. {
  35. if (detail::test_input(x, y)) throw comparison_error();
  36. const T& xl = x.lower();
  37. const T& yl = y.lower();
  38. return xl < yl || (xl == yl && x.upper() <= y.upper());
  39. }
  40. template<class T, class Policies> inline
  41. bool operator<=(const interval<T, Policies>& x, const T& y)
  42. {
  43. if (detail::test_input(x, y)) throw comparison_error();
  44. const T& xl = x.lower();
  45. return xl < y || (xl == y && x.upper() <= y);
  46. }
  47. template<class T, class Policies1, class Policies2> inline
  48. bool operator>(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
  49. {
  50. if (detail::test_input(x, y)) throw comparison_error();
  51. const T& xl = x.lower();
  52. const T& yl = y.lower();
  53. return xl > yl || (xl == yl && x.upper() > y.upper());
  54. }
  55. template<class T, class Policies> inline
  56. bool operator>(const interval<T, Policies>& x, const T& y)
  57. {
  58. if (detail::test_input(x, y)) throw comparison_error();
  59. const T& xl = x.lower();
  60. return xl > y || (xl == y && x.upper() > y);
  61. }
  62. template<class T, class Policies1, class Policies2> inline
  63. bool operator>=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
  64. {
  65. if (detail::test_input(x, y)) throw comparison_error();
  66. const T& xl = x.lower();
  67. const T& yl = y.lower();
  68. return xl > yl || (xl == yl && x.upper() >= y.upper());
  69. }
  70. template<class T, class Policies> inline
  71. bool operator>=(const interval<T, Policies>& x, const T& y)
  72. {
  73. if (detail::test_input(x, y)) throw comparison_error();
  74. return x.lower() >= y;
  75. }
  76. template<class T, class Policies1, class Policies2> inline
  77. bool operator==(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
  78. {
  79. if (detail::test_input(x, y)) throw comparison_error();
  80. return x.lower() == y.lower() && x.upper() == y.upper();
  81. }
  82. template<class T, class Policies> inline
  83. bool operator==(const interval<T, Policies>& x, const T& y)
  84. {
  85. if (detail::test_input(x, y)) throw comparison_error();
  86. return x.lower() == y && x.upper() == y;
  87. }
  88. template<class T, class Policies1, class Policies2> inline
  89. bool operator!=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
  90. {
  91. if (detail::test_input(x, y)) throw comparison_error();
  92. return x.lower() != y.lower() || x.upper() != y.upper();
  93. }
  94. template<class T, class Policies> inline
  95. bool operator!=(const interval<T, Policies>& x, const T& y)
  96. {
  97. if (detail::test_input(x, y)) throw comparison_error();
  98. return x.lower() != y || x.upper() != y;
  99. }
  100. } // namespace lexicographic
  101. } // namespace compare
  102. } // namespace interval_lib
  103. } // namespace numeric
  104. } // namespace boost
  105. #endif // BOOST_NUMERIC_INTERVAL_COMPARE_LEXICOGRAPHIC_HPP