summaryrefslogtreecommitdiff
path: root/boost/spirit/home/x3/support/subcontext.hpp
blob: 7614fcbcae88b7fe14b1d427e5e72ece633df66f (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
/*=============================================================================
    Copyright (c) 2001-2014 Joel de Guzman
    Copyright (c) 2013 Agustín Bergé
    http://spirit.sourceforge.net/

    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)
=============================================================================*/
#if !defined(BOOST_SPIRIT_X3_SUBCONTEXT_APR_15_2013_0840AM)
#define BOOST_SPIRIT_X3_SUBCONTEXT_APR_15_2013_0840AM

#if defined(_MSC_VER)
#pragma once
#endif

#include <boost/fusion/support/pair.hpp>
#include <boost/spirit/home/x3/support/context.hpp>
#include <boost/spirit/home/x3/support/unused.hpp>

namespace boost { namespace spirit { namespace x3
{
    template <typename... T>
    struct subcontext;

    template <>
    struct subcontext<>
    {
        template <typename Context>
        subcontext(Context const& /*context*/)
        {}
        
        template <typename ID_, typename Unused = void>
        struct get_result
        {
            typedef unused_type type;
        };

        template <typename ID_>
        unused_type
        get(ID_) const
        {
            return unused;
        }
    };

    template <typename T>
    struct subcontext<T>
      : context<typename T::first_type, typename T::second_type>
    {
        typedef context<
            typename T::first_type, typename T::second_type
        > context_type;

        template <typename Context>
        subcontext(Context const& context)
          : context_type(x3::get<typename T::first_type>(context))
        {}

        using context_type::get;
    };

    template <typename T, typename... Tail>
    struct subcontext<T, Tail...>
      : subcontext<Tail...>
      , context<
            typename T::first_type, typename T::second_type
          , subcontext<Tail...>
        >
    {
        typedef subcontext<Tail...> base_type;
        typedef context<
            typename T::first_type, typename T::second_type
          , base_type
        > context_type;

        template <typename Context>
        subcontext(Context const& context)
          : base_type(context)
          , context_type(
                x3::get<typename T::first_type>(context)
              , *static_cast<base_type*>(this))
        {}

        using context_type::get;
    };

}}}

#endif