]> git.sesse.net Git - casparcg/blob - dependencies/boost/boost/spirit/home/phoenix/core/composite.hpp
Manually merged pull request #222
[casparcg] / dependencies / boost / boost / spirit / home / phoenix / core / composite.hpp
1 /*=============================================================================
2     Copyright (c) 2001-2007 Joel de Guzman
3
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 PHOENIX_CORE_COMPOSITE_HPP
8 #define PHOENIX_CORE_COMPOSITE_HPP
9
10 #include <boost/spirit/home/phoenix/core/actor.hpp>
11 #include <boost/spirit/home/phoenix/core/is_actor.hpp>
12 #include <boost/fusion/include/vector.hpp>
13 #include <boost/fusion/include/at.hpp>
14 #include <boost/fusion/include/size.hpp>
15 #include <boost/fusion/include/mpl.hpp>
16 #include <boost/mpl/fold.hpp>
17 #include <boost/mpl/bool.hpp>
18 #include <boost/mpl/or.hpp>
19
20 namespace boost { namespace phoenix
21 {
22     namespace detail
23     {
24         template <int N>
25         struct composite_eval;
26         
27         struct compute_no_nullary
28         {
29             template <typename State, typename T>
30             struct apply
31             {
32                 typedef typename 
33                     mpl::or_<typename T::no_nullary, State>::type
34                 type;
35             };
36         };
37     }
38
39     template <typename EvalPolicy, typename EvalTuple>
40     struct composite : EvalTuple
41     {
42         typedef EvalTuple base_type;
43         typedef composite<EvalPolicy, EvalTuple> self_type;
44         typedef EvalPolicy eval_policy_type;
45         
46         typedef typename
47             mpl::fold<
48                 EvalTuple
49               , mpl::false_
50               , detail::compute_no_nullary
51             >::type
52         no_nullary;
53
54         template <typename Env>
55         struct result
56         {
57             typedef
58                 typename detail::composite_eval<
59                     fusion::result_of::size<base_type>::value>::
60                 template result<self_type, Env>::type
61             type;
62         };
63
64         composite()
65             : base_type() {}
66
67         composite(base_type const& base)
68             : base_type(base) {}
69
70         template <typename U0>
71         composite(U0& _0)
72             : base_type(_0) {}
73
74         template <typename U0, typename U1>
75         composite(U0& _0, U1& _1)
76             : base_type(_0, _1) {}
77
78         template <typename Env>
79         typename result<Env>::type
80         eval(Env const& env) const
81         {
82             typedef typename result<Env>::type return_type;
83             return detail::
84                 composite_eval<fusion::result_of::size<base_type>::value>::template
85                     call<return_type>(*this, env);
86         }
87
88         //  Bring in the rest of the constructors
89         #include <boost/spirit/home/phoenix/core/detail/composite.hpp>
90     };
91
92     //  Bring in the detail::composite_eval<0..N> definitions
93     #include <boost/spirit/home/phoenix/core/detail/composite_eval.hpp>
94 }}
95
96 #endif