os/ossrv/ossrv_pub/boost_apis/boost/numeric/interval/checking.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/numeric/interval/checking.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,130 @@
     1.4 +/* Boost interval/checking.hpp template implementation file
     1.5 + *
     1.6 + * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion
     1.7 + *
     1.8 + * Distributed under the Boost Software License, Version 1.0.
     1.9 + * (See accompanying file LICENSE_1_0.txt or
    1.10 + * copy at http://www.boost.org/LICENSE_1_0.txt)
    1.11 + */
    1.12 +
    1.13 +#ifndef BOOST_NUMERIC_INTERVAL_CHECKING_HPP
    1.14 +#define BOOST_NUMERIC_INTERVAL_CHECKING_HPP
    1.15 +
    1.16 +#include <stdexcept>
    1.17 +#include <string>
    1.18 +#include <cassert>
    1.19 +#include <boost/limits.hpp>
    1.20 +
    1.21 +namespace boost {
    1.22 +namespace numeric {
    1.23 +namespace interval_lib {
    1.24 +
    1.25 +struct exception_create_empty
    1.26 +{
    1.27 +  void operator()()
    1.28 +  {
    1.29 +    throw std::runtime_error("boost::interval: empty interval created");
    1.30 +  }
    1.31 +};
    1.32 +
    1.33 +struct exception_invalid_number
    1.34 +{
    1.35 +  void operator()()
    1.36 +  {
    1.37 +    throw std::invalid_argument("boost::interval: invalid number");
    1.38 +  }
    1.39 +};
    1.40 +
    1.41 +template<class T>
    1.42 +struct checking_base
    1.43 +{
    1.44 +  static T pos_inf()
    1.45 +  {
    1.46 +    assert(std::numeric_limits<T>::has_infinity);
    1.47 +    return std::numeric_limits<T>::infinity();
    1.48 +  }
    1.49 +  static T neg_inf()
    1.50 +  {
    1.51 +    assert(std::numeric_limits<T>::has_infinity);
    1.52 +    return -std::numeric_limits<T>::infinity();
    1.53 +  }
    1.54 +  static T nan()
    1.55 +  {
    1.56 +    assert(std::numeric_limits<T>::has_quiet_NaN);
    1.57 +    return std::numeric_limits<T>::quiet_NaN();
    1.58 +  }
    1.59 +  static bool is_nan(const T& x)
    1.60 +  {
    1.61 +    return std::numeric_limits<T>::has_quiet_NaN && (x != x);
    1.62 +  }
    1.63 +  static T empty_lower()
    1.64 +  {
    1.65 +    return (std::numeric_limits<T>::has_quiet_NaN ?
    1.66 +            std::numeric_limits<T>::quiet_NaN() : static_cast<T>(1));
    1.67 +  }
    1.68 +  static T empty_upper()
    1.69 +  {
    1.70 +    return (std::numeric_limits<T>::has_quiet_NaN ?
    1.71 +            std::numeric_limits<T>::quiet_NaN() : static_cast<T>(0));
    1.72 +  }
    1.73 +  static bool is_empty(const T& l, const T& u)
    1.74 +  {
    1.75 +    return !(l <= u); // safety for partial orders
    1.76 +  }
    1.77 +};
    1.78 +
    1.79 +template<class T, class Checking = checking_base<T>,
    1.80 +         class Exception = exception_create_empty>
    1.81 +struct checking_no_empty: Checking
    1.82 +{
    1.83 +  static T nan()
    1.84 +  {
    1.85 +    assert(false);
    1.86 +    return Checking::nan();
    1.87 +  }
    1.88 +  static T empty_lower()
    1.89 +  {
    1.90 +    Exception()();
    1.91 +    return Checking::empty_lower();
    1.92 +  }
    1.93 +  static T empty_upper()
    1.94 +  {
    1.95 +    Exception()();
    1.96 +    return Checking::empty_upper();
    1.97 +  }
    1.98 +  static bool is_empty(const T&, const T&)
    1.99 +  {
   1.100 +    return false;
   1.101 +  }
   1.102 +};
   1.103 +
   1.104 +template<class T, class Checking = checking_base<T> >
   1.105 +struct checking_no_nan: Checking
   1.106 +{
   1.107 +  static bool is_nan(const T&)
   1.108 +  {
   1.109 +    return false;
   1.110 +  }
   1.111 +};
   1.112 +
   1.113 +template<class T, class Checking = checking_base<T>,
   1.114 +         class Exception = exception_invalid_number>
   1.115 +struct checking_catch_nan: Checking
   1.116 +{
   1.117 +  static bool is_nan(const T& x)
   1.118 +  {
   1.119 +    if (Checking::is_nan(x)) Exception()();
   1.120 +    return false;
   1.121 +  }
   1.122 +};
   1.123 +
   1.124 +template<class T>
   1.125 +struct checking_strict:
   1.126 +  checking_no_nan<T, checking_no_empty<T> >
   1.127 +{};
   1.128 +
   1.129 +} // namespace interval_lib
   1.130 +} // namespace numeric
   1.131 +} // namespace boost
   1.132 +
   1.133 +#endif // BOOST_NUMERIC_INTERVAL_CHECKING_HPP