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