summaryrefslogtreecommitdiffstats
blob: 1679cb2b3858e9c37b8e61877164a006019450f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*=============================================================================
    Copyright (c) 2001-2007 Joel de Guzman

    Distributed under the Boost Software License, Version 1.0. (See accompanying 
    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#ifndef PHOENIX_CORE_ARGUMENT_HPP
#define PHOENIX_CORE_ARGUMENT_HPP

#include <boost/preprocessor/repetition/repeat_from_to.hpp>
#include <boost/preprocessor/inc.hpp>
#include <boost/spirit/home/phoenix/core/actor.hpp>
#include <boost/fusion/include/at.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/mpl/less.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/at.hpp>
#include <boost/mpl/size.hpp>
#include <boost/type_traits/add_reference.hpp>

#define PHOENIX_DECLARE_ARG(z, n, data)                                       \
    typedef actor<argument<n> >                                               \
        BOOST_PP_CAT(BOOST_PP_CAT(arg, BOOST_PP_INC(n)), _type);              \
    actor<argument<n> > const                                                 \
        BOOST_PP_CAT(arg, BOOST_PP_INC(n)) = argument<n>();                   \
    typedef actor<argument<n> >                                               \
        BOOST_PP_CAT(BOOST_PP_CAT(_, BOOST_PP_INC(n)), _type);                \
    actor<argument<n> > const                                                 \
        BOOST_PP_CAT(_, BOOST_PP_INC(n)) = argument<n>();

namespace boost { namespace phoenix
{
    namespace detail
    {
        template <typename Arg>
        struct error_argument_not_found {};
        inline void test_invalid_argument(int) {}
    }

    template <int N>
    struct argument
    {
        typedef mpl::true_ no_nullary;

        template <typename Env>
        struct result
        {
            typedef typename
                fusion::result_of::at<typename Env::tie_type, mpl::int_<N> >::type
            type;
        };

        template <typename Env>
        typename result<Env>::type
        eval(Env const& env) const
        {
            typedef typename
                mpl::if_<
                    mpl::less<mpl::int_<N>, mpl::size<typename Env::args_type> >
                  , int
                  , detail::error_argument_not_found<argument<N> >
                >::type
            check_out_of_bounds;

            detail::test_invalid_argument(check_out_of_bounds());
            return fusion::at_c<N>(env.args());
        }
    };

    namespace arg_names
    {
    //  Phoenix style names
        typedef actor<argument<0> > arg1_type;
        actor<argument<0> > const arg1 = argument<0>();
        typedef actor<argument<1> > arg2_type;
        actor<argument<1> > const arg2 = argument<1>();
        typedef actor<argument<2> > arg3_type;
        actor<argument<2> > const arg3 = argument<2>();

    //  BLL style names
        typedef actor<argument<0> > _1_type;
        actor<argument<0> > const _1 = argument<0>();
        typedef actor<argument<1> > _2_type;
        actor<argument<1> > const _2 = argument<1>();
        typedef actor<argument<2> > _3_type;
        actor<argument<2> > const _3 = argument<2>();

    //  Bring in the rest or the Phoenix style arguments (arg4 .. argN+1)
    //  and BLL style arguments (_4 .. _N+1), using PP
        BOOST_PP_REPEAT_FROM_TO(
            3, PHOENIX_ARG_LIMIT, PHOENIX_DECLARE_ARG, _)
    }
}}

#undef PHOENIX_DECLARE_ARG
#endif