phx2_result.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*=============================================================================
  2. Copyright (c) 2011 Thomas Heller
  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_CORE_DETAIL_PHX2_RESULT_HPP
  7. #define BOOST_PHOENIX_CORE_DETAIL_PHX2_RESULT_HPP
  8. #include <boost/phoenix/core/limits.hpp>
  9. #include <boost/phoenix/support/iterate.hpp>
  10. #include <boost/mpl/has_xxx.hpp>
  11. #include <boost/mpl/bool.hpp>
  12. namespace boost { namespace phoenix {
  13. namespace detail
  14. {
  15. BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type)
  16. template <typename Result>
  17. struct has_phx2_result_impl
  18. {
  19. typedef char yes;
  20. typedef char (&no)[2];
  21. template <typename A>
  22. static yes check_(typename A::type *);
  23. template <typename A>
  24. static no check_(...);
  25. static bool const value = (sizeof(yes) == sizeof(check_<Result>(0)));
  26. typedef boost::mpl::bool_<value> type;
  27. };
  28. #ifdef BOOST_PHOENIX_NO_VARIADIC_PHX2_RESULT
  29. #include <boost/phoenix/core/detail/cpp03/phx2_result.hpp>
  30. #else
  31. template <typename F, typename... A>
  32. struct has_phx2_result
  33. : mpl::eval_if<
  34. has_result_type<F>
  35. , mpl::false_
  36. , has_phx2_result_impl<typename F::template result<F(A...)> >
  37. >::type
  38. {};
  39. template <typename F, typename... A>
  40. struct phx2_result
  41. {
  42. typedef typename F::template result<A...>::type type;
  43. };
  44. template <typename F, typename... A>
  45. struct phx2_result<F, A &...>
  46. {
  47. typedef typename F::template result<A...>::type type;
  48. };
  49. template <typename F, typename... A>
  50. struct phx2_result<F, A const &...>
  51. {
  52. typedef typename F::template result<A...>::type type;
  53. };
  54. #endif
  55. }
  56. }}
  57. #endif