is_numeric.hpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*-----------------------------------------------------------------------------+
  2. Copyright (c) 2010-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_TYPE_TRAITS_IS_NUMERIC_HPP_JOFA_100322
  9. #define BOOST_ICL_TYPE_TRAITS_IS_NUMERIC_HPP_JOFA_100322
  10. #include <limits>
  11. #include <complex>
  12. #include <functional>
  13. #include <boost/type_traits/is_floating_point.hpp>
  14. #include <boost/type_traits/is_integral.hpp>
  15. namespace boost{ namespace icl
  16. {
  17. template <class Type> struct is_fixed_numeric
  18. {
  19. typedef is_fixed_numeric type;
  20. BOOST_STATIC_CONSTANT(bool, value = (0 < std::numeric_limits<Type>::digits));
  21. };
  22. template <class Type> struct is_std_numeric
  23. {
  24. typedef is_std_numeric type;
  25. BOOST_STATIC_CONSTANT(bool,
  26. value = (std::numeric_limits<Type>::is_specialized));
  27. };
  28. template <class Type> struct is_std_integral
  29. {
  30. typedef is_std_integral type;
  31. BOOST_STATIC_CONSTANT(bool,
  32. value = (std::numeric_limits<Type>::is_integer));
  33. };
  34. template <class Type> struct is_numeric
  35. {
  36. typedef is_numeric type;
  37. BOOST_STATIC_CONSTANT(bool, value =
  38. (mpl::or_< is_std_numeric<Type>
  39. , boost::is_integral<Type>
  40. , is_std_integral<Type> >::value) );
  41. };
  42. template <class Type>
  43. struct is_numeric<std::complex<Type> >
  44. {
  45. typedef is_numeric type;
  46. BOOST_STATIC_CONSTANT(bool, value = true);
  47. };
  48. //--------------------------------------------------------------------------
  49. template<class Type, class Compare, bool Enable = false>
  50. struct numeric_minimum
  51. {
  52. static bool is_less_than(Type){ return true; }
  53. static bool is_less_than_or(Type, bool){ return true; }
  54. };
  55. template<class Type>
  56. struct numeric_minimum<Type, std::less<Type>, true>
  57. {
  58. static bool is_less_than(Type value)
  59. { return std::less<Type>()((std::numeric_limits<Type>::min)(), value); }
  60. static bool is_less_than_or(Type value, bool cond)
  61. { return cond || is_less_than(value); }
  62. };
  63. template<class Type>
  64. struct numeric_minimum<Type, std::greater<Type>, true>
  65. {
  66. static bool is_less_than(Type value)
  67. { return std::greater<Type>()((std::numeric_limits<Type>::max)(), value); }
  68. static bool is_less_than_or(Type value, bool cond)
  69. { return cond || is_less_than(value); }
  70. };
  71. //--------------------------------------------------------------------------
  72. template<class Type>
  73. struct is_non_floating_point
  74. {
  75. typedef is_non_floating_point type;
  76. BOOST_STATIC_CONSTANT(bool, value =
  77. (mpl::not_< is_floating_point<Type> >::value));
  78. };
  79. }} // namespace boost icl
  80. #endif