]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #ifndef BOOST_METAPARSE_V1_FOLDL_REJECT_INCOMPLETE_HPP |
2 | #define BOOST_METAPARSE_V1_FOLDL_REJECT_INCOMPLETE_HPP | |
3 | ||
4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. | |
5 | // Distributed under the Boost Software License, Version 1.0. | |
6 | // (See accompanying file LICENSE_1_0.txt or copy at | |
7 | // http://www.boost.org/LICENSE_1_0.txt) | |
8 | ||
9 | #include <boost/metaparse/v1/fail_at_first_char_expected.hpp> | |
10 | #include <boost/metaparse/v1/is_error.hpp> | |
11 | #include <boost/metaparse/v1/get_position.hpp> | |
12 | #include <boost/metaparse/v1/get_result.hpp> | |
13 | #include <boost/metaparse/v1/get_remaining.hpp> | |
14 | ||
15 | #include <boost/mpl/eval_if.hpp> | |
16 | #include <boost/mpl/equal_to.hpp> | |
17 | ||
18 | namespace boost | |
19 | { | |
20 | namespace metaparse | |
21 | { | |
22 | namespace v1 | |
23 | { | |
24 | template <class P, class State, class ForwardOp> | |
25 | struct foldl_reject_incomplete | |
26 | { | |
27 | private: | |
28 | template <class Res> | |
29 | struct apply_unchecked : | |
30 | // I need to use apply_wrap, and not apply, because apply would | |
31 | // build a metafunction class from foldl<P, State, ForwardOp> | |
32 | // when ForwardOp is a lambda expression. | |
33 | foldl_reject_incomplete< | |
34 | P, | |
35 | typename ForwardOp::template apply< | |
36 | typename State::type, | |
37 | typename get_result<Res>::type | |
38 | >, | |
39 | ForwardOp | |
40 | >::template apply< | |
41 | typename get_remaining<Res>::type, | |
42 | typename get_position<Res>::type | |
43 | > | |
44 | {}; | |
45 | ||
46 | template <class S, class Pos> | |
47 | struct accept_state : accept<typename State::type, S, Pos> {}; | |
48 | ||
49 | template <class S, class Pos> | |
50 | struct end_of_folding : | |
51 | boost::mpl::eval_if< | |
52 | typename boost::mpl::equal_to< | |
53 | typename Pos::type, | |
54 | typename get_position<typename P::template apply<S, Pos> >::type | |
55 | >::type, | |
56 | accept_state<S, Pos>, | |
57 | typename P::template apply<S, Pos> | |
58 | > | |
59 | {}; | |
60 | public: | |
61 | typedef foldl_reject_incomplete type; | |
62 | ||
63 | template <class S, class Pos> | |
64 | struct apply : | |
65 | boost::mpl::eval_if< | |
66 | typename is_error<typename P::template apply<S, Pos> >::type, | |
67 | end_of_folding<S, Pos>, | |
68 | apply_unchecked<typename P::template apply<S, Pos> > | |
69 | > | |
70 | {}; | |
71 | }; | |
72 | } | |
73 | } | |
74 | } | |
75 | ||
76 | #endif | |
77 |