Update contrib.
1 /* Boost interval/checking.hpp template implementation file
3 * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion
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_CHECKING_HPP
11 #define BOOST_NUMERIC_INTERVAL_CHECKING_HPP
16 #include <boost/limits.hpp>
20 namespace interval_lib {
22 struct exception_create_empty
26 throw std::runtime_error("boost::interval: empty interval created");
30 struct exception_invalid_number
34 throw std::invalid_argument("boost::interval: invalid number");
43 assert(std::numeric_limits<T>::has_infinity);
44 return std::numeric_limits<T>::infinity();
48 assert(std::numeric_limits<T>::has_infinity);
49 return -std::numeric_limits<T>::infinity();
53 assert(std::numeric_limits<T>::has_quiet_NaN);
54 return std::numeric_limits<T>::quiet_NaN();
56 static bool is_nan(const T& x)
58 return std::numeric_limits<T>::has_quiet_NaN && (x != x);
60 static T empty_lower()
62 return (std::numeric_limits<T>::has_quiet_NaN ?
63 std::numeric_limits<T>::quiet_NaN() : static_cast<T>(1));
65 static T empty_upper()
67 return (std::numeric_limits<T>::has_quiet_NaN ?
68 std::numeric_limits<T>::quiet_NaN() : static_cast<T>(0));
70 static bool is_empty(const T& l, const T& u)
72 return !(l <= u); // safety for partial orders
76 template<class T, class Checking = checking_base<T>,
77 class Exception = exception_create_empty>
78 struct checking_no_empty: Checking
83 return Checking::nan();
85 static T empty_lower()
88 return Checking::empty_lower();
90 static T empty_upper()
93 return Checking::empty_upper();
95 static bool is_empty(const T&, const T&)
101 template<class T, class Checking = checking_base<T> >
102 struct checking_no_nan: Checking
104 static bool is_nan(const T&)
110 template<class T, class Checking = checking_base<T>,
111 class Exception = exception_invalid_number>
112 struct checking_catch_nan: Checking
114 static bool is_nan(const T& x)
116 if (Checking::is_nan(x)) Exception()();
122 struct checking_strict:
123 checking_no_nan<T, checking_no_empty<T> >
126 } // namespace interval_lib
127 } // namespace numeric
130 #endif // BOOST_NUMERIC_INTERVAL_CHECKING_HPP