]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/spirit/home/x3/directive/with.hpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / boost / spirit / home / x3 / directive / with.hpp
1 /*=============================================================================
2 Copyright (c) 2014 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 BOOST_SPIRIT_X3_DIRECTIVE_WITH_HPP
8 #define BOOST_SPIRIT_X3_DIRECTIVE_WITH_HPP
9
10 #include <boost/spirit/home/x3/support/unused.hpp>
11 #include <boost/spirit/home/x3/core/parser.hpp>
12
13 namespace boost { namespace spirit { namespace x3
14 {
15 ///////////////////////////////////////////////////////////////////////////
16 // with directive injects a value into the context prior to parsing.
17 ///////////////////////////////////////////////////////////////////////////
18 template <typename Subject, typename Derived, typename T>
19 struct with_value_holder
20 : unary_parser<Subject, Derived>
21 {
22 typedef unary_parser<Subject, Derived> base_type;
23 mutable T val;
24 constexpr with_value_holder(Subject const& subject, T&& val)
25 : base_type(subject)
26 , val(std::forward<T>(val)) {}
27 };
28
29 template <typename Subject, typename Derived, typename T>
30 struct with_value_holder<Subject, Derived, T&>
31 : unary_parser<Subject, Derived>
32 {
33 typedef unary_parser<Subject, Derived> base_type;
34 T& val;
35 constexpr with_value_holder(Subject const& subject, T& val)
36 : base_type(subject)
37 , val(val) {}
38 };
39
40 template <typename Subject, typename ID, typename T>
41 struct with_directive
42 : with_value_holder<Subject, with_directive<Subject, ID, T>, T>
43 {
44 typedef with_value_holder<Subject, with_directive<Subject, ID, T>, T> base_type;
45 static bool const is_pass_through_unary = true;
46 static bool const handles_container = Subject::handles_container;
47
48 typedef Subject subject_type;
49
50 constexpr with_directive(Subject const& subject, T&& val)
51 : base_type(subject, std::forward<T>(val)) {}
52
53 template <typename Iterator, typename Context
54 , typename RContext, typename Attribute>
55 bool parse(Iterator& first, Iterator const& last
56 , Context const& context, RContext& rcontext, Attribute& attr) const
57 {
58 return this->subject.parse(
59 first, last
60 , make_context<ID>(this->val, context)
61 , rcontext
62 , attr);
63 }
64 };
65
66 template <typename ID, typename T>
67 struct with_gen
68 {
69 T&& val;
70
71 template <typename Subject>
72 constexpr with_directive<typename extension::as_parser<Subject>::value_type, ID, T>
73 operator[](Subject const& subject) const
74 {
75 return { as_parser(subject), std::forward<T>(val) };
76 }
77 };
78
79 template <typename ID, typename T>
80 constexpr with_gen<ID, T> with(T&& val)
81 {
82 return { std::forward<T>(val) };
83 }
84 }}}
85
86 #endif