cmath.hpp 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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/declval.hpp>
  12. #include <boost/phoenix/support/iterate.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_RESULT_TYPE(name, n) \
  18. typename proto::detail::uncvref<A0>::type
  19. #else
  20. #define BOOST_PHOENIX_MATH_FUNCTION_RESULT_TYPE(name, n) \
  21. decltype(name(BOOST_PP_ENUM_BINARY_PARAMS( \
  22. n \
  23. , boost::declval<typename proto::detail::uncvref<A \
  24. , >::type>() BOOST_PP_INTERCEPT)))
  25. #endif
  26. #define BOOST_PHOENIX_MATH_FUNCTION(name, n) \
  27. namespace phoenix_impl { \
  28. struct name ## _impl { \
  29. template<class Sig> \
  30. struct result; \
  31. template<class This, BOOST_PHOENIX_typename_A(n)> \
  32. struct result<This(BOOST_PHOENIX_A(n))> \
  33. { \
  34. typedef \
  35. BOOST_PHOENIX_MATH_FUNCTION_RESULT_TYPE(name, n) \
  36. type; \
  37. }; \
  38. template<BOOST_PHOENIX_typename_A(n)> \
  39. typename result<name ## _impl(BOOST_PHOENIX_A(n))>::type \
  40. operator()(BOOST_PHOENIX_A_const_ref_a(n)) const { \
  41. using namespace std; \
  42. return name(BOOST_PHOENIX_a(n)); \
  43. } \
  44. }; \
  45. } \
  46. namespace phoenix { \
  47. BOOST_PHOENIX_ADAPT_CALLABLE(name, phoenix_impl::name ## _impl, n) \
  48. }
  49. BOOST_PHOENIX_MATH_FUNCTION(acos, 1)
  50. BOOST_PHOENIX_MATH_FUNCTION(asin, 1)
  51. BOOST_PHOENIX_MATH_FUNCTION(atan, 1)
  52. BOOST_PHOENIX_MATH_FUNCTION(atan2, 2)
  53. BOOST_PHOENIX_MATH_FUNCTION(ceil, 1)
  54. BOOST_PHOENIX_MATH_FUNCTION(cos, 1)
  55. BOOST_PHOENIX_MATH_FUNCTION(cosh, 1)
  56. BOOST_PHOENIX_MATH_FUNCTION(exp, 1)
  57. BOOST_PHOENIX_MATH_FUNCTION(fabs, 1)
  58. BOOST_PHOENIX_MATH_FUNCTION(floor, 1)
  59. BOOST_PHOENIX_MATH_FUNCTION(fmod, 2)
  60. BOOST_PHOENIX_MATH_FUNCTION(frexp, 2)
  61. BOOST_PHOENIX_MATH_FUNCTION(ldexp, 2)
  62. BOOST_PHOENIX_MATH_FUNCTION(log, 1)
  63. BOOST_PHOENIX_MATH_FUNCTION(log10, 1)
  64. BOOST_PHOENIX_MATH_FUNCTION(modf, 2)
  65. BOOST_PHOENIX_MATH_FUNCTION(pow, 2)
  66. BOOST_PHOENIX_MATH_FUNCTION(sin, 1)
  67. BOOST_PHOENIX_MATH_FUNCTION(sinh, 1)
  68. BOOST_PHOENIX_MATH_FUNCTION(sqrt, 1)
  69. BOOST_PHOENIX_MATH_FUNCTION(tan, 1)
  70. BOOST_PHOENIX_MATH_FUNCTION(tanh, 1)
  71. #undef BOOST_PHOENIX_MATH_FUNCTION
  72. }
  73. #endif