1 /* Boost interval/compare/lexicographic.hpp template implementation file
3 * Copyright 2002-2003 Guillaume Melquiond
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)
10 #ifndef BOOST_NUMERIC_INTERVAL_COMPARE_LEXICOGRAPHIC_HPP
11 #define BOOST_NUMERIC_INTERVAL_COMPARE_LEXICOGRAPHIC_HPP
13 #include <boost/numeric/interval/detail/interval_prototype.hpp>
14 #include <boost/numeric/interval/detail/test_input.hpp>
18 namespace interval_lib {
20 namespace lexicographic {
22 template<class T, class Policies1, class Policies2> inline
23 bool operator<(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
25 if (detail::test_input(x, y)) throw comparison_error();
26 const T& xl = x.lower();
27 const T& yl = y.lower();
28 return xl < yl || (xl == yl && x.upper() < y.upper());
31 template<class T, class Policies> inline
32 bool operator<(const interval<T, Policies>& x, const T& y)
34 if (detail::test_input(x, y)) throw comparison_error();
38 template<class T, class Policies1, class Policies2> inline
39 bool operator<=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
41 if (detail::test_input(x, y)) throw comparison_error();
42 const T& xl = x.lower();
43 const T& yl = y.lower();
44 return xl < yl || (xl == yl && x.upper() <= y.upper());
47 template<class T, class Policies> inline
48 bool operator<=(const interval<T, Policies>& x, const T& y)
50 if (detail::test_input(x, y)) throw comparison_error();
51 const T& xl = x.lower();
52 return xl < y || (xl == y && x.upper() <= y);
55 template<class T, class Policies1, class Policies2> inline
56 bool operator>(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
58 if (detail::test_input(x, y)) throw comparison_error();
59 const T& xl = x.lower();
60 const T& yl = y.lower();
61 return xl > yl || (xl == yl && x.upper() > y.upper());
64 template<class T, class Policies> inline
65 bool operator>(const interval<T, Policies>& x, const T& y)
67 if (detail::test_input(x, y)) throw comparison_error();
68 const T& xl = x.lower();
69 return xl > y || (xl == y && x.upper() > y);
72 template<class T, class Policies1, class Policies2> inline
73 bool operator>=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
75 if (detail::test_input(x, y)) throw comparison_error();
76 const T& xl = x.lower();
77 const T& yl = y.lower();
78 return xl > yl || (xl == yl && x.upper() >= y.upper());
81 template<class T, class Policies> inline
82 bool operator>=(const interval<T, Policies>& x, const T& y)
84 if (detail::test_input(x, y)) throw comparison_error();
85 return x.lower() >= y;
88 template<class T, class Policies1, class Policies2> inline
89 bool operator==(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
91 if (detail::test_input(x, y)) throw comparison_error();
92 return x.lower() == y.lower() && x.upper() == y.upper();
95 template<class T, class Policies> inline
96 bool operator==(const interval<T, Policies>& x, const T& y)
98 if (detail::test_input(x, y)) throw comparison_error();
99 return x.lower() == y && x.upper() == y;
102 template<class T, class Policies1, class Policies2> inline
103 bool operator!=(const interval<T, Policies1>& x, const interval<T, Policies2>& y)
105 if (detail::test_input(x, y)) throw comparison_error();
106 return x.lower() != y.lower() || x.upper() != y.upper();
109 template<class T, class Policies> inline
110 bool operator!=(const interval<T, Policies>& x, const T& y)
112 if (detail::test_input(x, y)) throw comparison_error();
113 return x.lower() != y || x.upper() != y;
116 } // namespace lexicographic
117 } // namespace compare
118 } // namespace interval_lib
119 } // namespace numeric
122 #endif // BOOST_NUMERIC_INTERVAL_COMPARE_LEXICOGRAPHIC_HPP