cmath.hpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*==============================================================================
  2. Copyright (c) 2011 Steven Watanabe
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #ifndef BOOST_PHOENIX_CMATH_HPP_INCLUDED
  7. #define BOOST_PHOENIX_CMATH_HPP_INCLUDED
  8. #include <boost/phoenix/core/limits.hpp>
  9. #include <cmath>
  10. #include <boost/phoenix/function/adapt_callable.hpp>
  11. #include <boost/type_traits/remove_reference.hpp>
  12. #include <boost/type_traits/remove_cv.hpp>
  13. namespace boost {
  14. #if (defined (BOOST_NO_CXX11_DECLTYPE) || \
  15. defined (BOOST_INTEL_CXX_VERSION) || \
  16. (BOOST_GCC_VERSION < 40500) )
  17. #define BOOST_PHOENIX_MATH_FUNCTION(name, n) \
  18. namespace phoenix_impl { \
  19. struct name ## _impl { \
  20. template<class Sig> \
  21. struct result; \
  22. template<class This, BOOST_PHOENIX_typename_A(n)> \
  23. struct result<This(BOOST_PHOENIX_A(n))> \
  24. { \
  25. typedef \
  26. typename proto::detail::uncvref<A0>::type \
  27. type; \
  28. }; \
  29. template<BOOST_PHOENIX_typename_A(n)> \
  30. A0 operator()(BOOST_PHOENIX_A_const_ref_a(n)) const { \
  31. using namespace std; \
  32. return name(BOOST_PHOENIX_a(n)); \
  33. } \
  34. }; \
  35. } \
  36. namespace phoenix { \
  37. BOOST_PHOENIX_ADAPT_CALLABLE(name, phoenix_impl::name ## _impl, n) \
  38. }
  39. #else
  40. #define BOOST_PHOENIX_MATH_FUNCTION(name, n) \
  41. namespace phoenix_impl { \
  42. struct name ## _impl { \
  43. template<class Sig> \
  44. struct result; \
  45. template<class This, BOOST_PHOENIX_typename_A(n)> \
  46. struct result<This(BOOST_PHOENIX_A(n))> \
  47. { \
  48. typedef \
  49. decltype( name(typename proto::detail::uncvref<A0>::type()) ) \
  50. type; \
  51. }; \
  52. template<BOOST_PHOENIX_typename_A(n)> \
  53. auto operator()(BOOST_PHOENIX_A_const_ref_a(n)) const -> decltype( name(BOOST_PHOENIX_a(n)) ) { \
  54. using namespace std; \
  55. return name(BOOST_PHOENIX_a(n)); \
  56. } \
  57. }; \
  58. } \
  59. namespace phoenix { \
  60. BOOST_PHOENIX_ADAPT_CALLABLE(name, phoenix_impl::name ## _impl, n) \
  61. }
  62. #endif
  63. BOOST_PHOENIX_MATH_FUNCTION(acos, 1)
  64. BOOST_PHOENIX_MATH_FUNCTION(asin, 1)
  65. BOOST_PHOENIX_MATH_FUNCTION(atan, 1)
  66. BOOST_PHOENIX_MATH_FUNCTION(atan2, 2)
  67. BOOST_PHOENIX_MATH_FUNCTION(ceil, 1)
  68. BOOST_PHOENIX_MATH_FUNCTION(cos, 1)
  69. BOOST_PHOENIX_MATH_FUNCTION(cosh, 1)
  70. BOOST_PHOENIX_MATH_FUNCTION(exp, 1)
  71. BOOST_PHOENIX_MATH_FUNCTION(fabs, 1)
  72. BOOST_PHOENIX_MATH_FUNCTION(floor, 1)
  73. BOOST_PHOENIX_MATH_FUNCTION(fmod, 2)
  74. BOOST_PHOENIX_MATH_FUNCTION(frexp, 2)
  75. BOOST_PHOENIX_MATH_FUNCTION(ldexp, 2)
  76. BOOST_PHOENIX_MATH_FUNCTION(log, 1)
  77. BOOST_PHOENIX_MATH_FUNCTION(log10, 1)
  78. BOOST_PHOENIX_MATH_FUNCTION(modf, 2)
  79. BOOST_PHOENIX_MATH_FUNCTION(pow, 2)
  80. BOOST_PHOENIX_MATH_FUNCTION(sin, 1)
  81. BOOST_PHOENIX_MATH_FUNCTION(sinh, 1)
  82. BOOST_PHOENIX_MATH_FUNCTION(sqrt, 1)
  83. BOOST_PHOENIX_MATH_FUNCTION(tan, 1)
  84. BOOST_PHOENIX_MATH_FUNCTION(tanh, 1)
  85. #undef BOOST_PHOENIX_MATH_FUNCTION
  86. }
  87. #endif