arity.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*==============================================================================
  2. Copyright (c) 2010 Thomas Heller
  3. Copyright (c) 2010 Eric Niebler
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ==============================================================================*/
  7. #ifndef BOOST_PHOENIX_CORE_ARITY_HPP
  8. #define BOOST_PHOENIX_CORE_ARITY_HPP
  9. #include <boost/phoenix/core/limits.hpp>
  10. #include <boost/is_placeholder.hpp>
  11. #include <boost/mpl/max.hpp>
  12. #include <boost/mpl/int.hpp>
  13. #include <boost/phoenix/core/meta_grammar.hpp>
  14. #include <boost/phoenix/core/terminal_fwd.hpp>
  15. #include <boost/phoenix/support/vector.hpp>
  16. #include <boost/proto/matches.hpp>
  17. #include <boost/proto/transform/fold.hpp>
  18. namespace boost { namespace phoenix
  19. {
  20. /////////////////////////////////////////////////////////////////////////////
  21. //
  22. // Calculate the arity of an expression using proto transforms
  23. //
  24. /////////////////////////////////////////////////////////////////////////////
  25. struct arity;
  26. namespace result_of
  27. {
  28. template <typename Expr>
  29. struct arity
  30. : mpl::int_<
  31. evaluator::impl<
  32. Expr const&
  33. , vector2<
  34. mpl::int_<0>
  35. , boost::phoenix::arity
  36. >&
  37. , proto::empty_env
  38. >::result_type::value
  39. >
  40. {};
  41. }
  42. struct arity
  43. {
  44. template <typename Rule, typename Dummy = void>
  45. struct when
  46. : proto::fold<
  47. proto::_
  48. , mpl::int_<0>
  49. , proto::make<mpl::max<
  50. proto::_state
  51. , proto::call<
  52. evaluator(
  53. proto::_
  54. , proto::call<
  55. functional::context(_env, _actions)
  56. >
  57. )
  58. >
  59. >()>
  60. >
  61. {};
  62. };
  63. template <typename Dummy>
  64. struct arity::when<rule::argument, Dummy>
  65. : proto::make<is_placeholder<proto::_value>()>
  66. {};
  67. template <typename Dummy>
  68. struct arity::when<rule::custom_terminal, Dummy>
  69. : proto::make<mpl::int_<0>()>
  70. {};
  71. template <typename Dummy>
  72. struct arity::when<rule::terminal, Dummy>
  73. : proto::make<mpl::int_<0>()>
  74. {};
  75. }}
  76. #endif