Stop using mpl::apply

This commit is contained in:
Abel Sinkovics
2015-09-08 20:27:29 +02:00
parent 0283507b71
commit 98c3b06b57
65 changed files with 441 additions and 362 deletions

View File

@@ -38,7 +38,7 @@ is equivalent to
p::apply<s, pos>::type
when `boost::mpl::apply<p, s, pos>` doesn't return an error and
when `p::apply<s, pos>` doesn't return an error and
`pred::apply<get_result<p::apply<s, pos>>>::type` is `true`. Otherwise it is
equivalent to

View File

@@ -32,8 +32,8 @@ For any `p` parser and `f` metafunction class accepting one argument
transform_error<p, f>::apply<s, pos>
is equivalent to `p::apply<s, pos>` when `p` accepts the input.
It is equivalent to `boost::mpl::apply<f, p::apply<s, pos>::type>` otherwise.
is equivalent to `p::apply<s, pos>` when `p` accepts the input. It is equivalent
to `f::apply<p::apply<s, pos>::type>` otherwise.
[h1 Example]

View File

@@ -33,7 +33,7 @@ For any `p` parser and `f` metafunction class accepting one argument
is equivalent to `p::apply<s, pos>` when `p` accepts the input.
It is equivalent to
`reject<boost::mpl::apply<f, get_message<p::apply<s, pos>>::type>, get_position<p::apply<s, pos>>>`
`reject<f::apply<get_message<p::apply<s, pos>>::type>, get_position<p::apply<s, pos>>>`
otherwise.
[h1 Example]

View File

@@ -10,7 +10,6 @@
#include <boost/metaparse/v1/reject.hpp>
#include <boost/metaparse/v1/is_error.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/eval_if.hpp>
@@ -29,11 +28,10 @@ namespace boost
template <class S, class Pos>
struct apply :
boost::mpl::eval_if<
typename boost::mpl::apply<
Pred,
typename get_result<boost::mpl::apply<P, S, Pos> >::type
typename Pred::template apply<
typename get_result<typename P::template apply<S, Pos> >::type
>::type,
boost::mpl::apply<P, S, Pos>,
typename P::template apply<S, Pos>,
reject<Msg, Pos>
>
{};
@@ -43,12 +41,11 @@ namespace boost
template <class S, class Pos>
struct apply :
boost::mpl::apply<
typename boost::mpl::if_<
is_error<boost::mpl::apply<P, S, Pos> >,
P,
unchecked
>::type,
boost::mpl::if_<
is_error<typename P::template apply<S, Pos> >,
P,
unchecked
>::type::template apply<
S,
Pos
>

View File

@@ -11,7 +11,6 @@
#include <boost/metaparse/v1/get_remaining.hpp>
#include <boost/metaparse/v1/get_position.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/eval_if.hpp>
namespace boost
@@ -38,9 +37,9 @@ namespace boost
template <class S, class Pos>
struct apply :
boost::mpl::eval_if<
typename is_error<boost::mpl::apply<P, S, Pos> >::type,
boost::mpl::apply<P, S, Pos>,
apply_unchecked<boost::mpl::apply<P, S, Pos> >
typename is_error<typename P::template apply<S, Pos> >::type,
typename P::template apply<S, Pos>,
apply_unchecked<typename P::template apply<S, Pos> >
>
{};
};

View File

@@ -15,7 +15,6 @@
#include <boost/metaparse/v1/get_col.hpp>
#include <boost/metaparse/v1/is_error.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/static_assert.hpp>
@@ -36,12 +35,12 @@ namespace boost
struct parsing_failed :
x__________________PARSING_FAILED__________________x<
get_line<
get_position<boost::mpl::apply<P, S, start> >
get_position<typename P::template apply<S, start> >
>::type::value,
get_col<
get_position<boost::mpl::apply<P, S, start> >
get_position<typename P::template apply<S, start> >
>::type::value,
typename get_message<boost::mpl::apply<P, S, start> >::type
typename get_message<typename P::template apply<S, start> >::type
>
{};
@@ -53,9 +52,9 @@ namespace boost
template <class S>
struct apply :
boost::mpl::eval_if<
typename is_error<boost::mpl::apply<P, S, start> >::type,
typename is_error<typename P::template apply<S, start> >::type,
parsing_failed<P, S>,
get_result<boost::mpl::apply<P, S, start> >
get_result<typename P::template apply<S, start> >
>
{};
};

View File

@@ -9,7 +9,6 @@
#include <boost/metaparse/v1/is_error.hpp>
#include <boost/metaparse/v1/reject.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/eval_if.hpp>
namespace boost
@@ -24,9 +23,9 @@ namespace boost
template <class S, class Pos>
struct apply :
boost::mpl::eval_if<
typename is_error<boost::mpl::apply<P, S, Pos> >::type,
typename is_error<typename P::template apply<S, Pos> >::type,
reject<Msg, Pos>,
boost::mpl::apply<P, S, Pos>
typename P::template apply<S, Pos>
>
{};

View File

@@ -11,7 +11,6 @@
#include <boost/metaparse/v1/is_error.hpp>
#include <boost/metaparse/v1/get_remaining.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/string.hpp>
@@ -33,9 +32,8 @@ namespace boost
using std::cout;
using std::endl;
using boost::mpl::c_str;
using boost::mpl::apply;
typedef display<typename apply<P, S, start>::type> runner;
typedef display<typename P::template apply<S, start>::type> runner;
cout << "Compile-time parsing results" << endl;
cout << "----------------------------" << endl;

View File

@@ -11,7 +11,6 @@
#include <boost/metaparse/v1/reject.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/apply.hpp>
namespace boost
{
@@ -27,7 +26,7 @@ namespace boost
template <class S, class Pos>
struct apply :
boost::mpl::if_<
is_error<boost::mpl::apply<P, S, Pos> >,
is_error<typename P::template apply<S, Pos> >,
accept<Result, S, Pos>,
reject<ErrorMsg, Pos>
>

View File

@@ -15,7 +15,6 @@
#include <boost/metaparse/v1/error/expected_to_fail.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/equal_to.hpp>
namespace boost
@@ -33,10 +32,10 @@ namespace boost
boost::mpl::eval_if<
typename boost::mpl::equal_to<
Pos,
typename get_position<boost::mpl::apply<P, S, Pos> >::type
typename get_position<typename P::template apply<S, Pos> >::type
>::type,
accept<impl::void_, S, Pos>,
boost::mpl::apply<P, S, Pos>
typename P::template apply<S, Pos>
>
{};
public:
@@ -45,7 +44,7 @@ namespace boost
template <class S, class Pos>
struct apply :
boost::mpl::eval_if<
typename is_error<boost::mpl::apply<P, S, Pos> >::type,
typename is_error<typename P::template apply<S, Pos> >::type,
apply_err<S, Pos>,
reject<error::expected_to_fail, Pos>
>

View File

@@ -13,8 +13,6 @@
#include <boost/metaparse/v1/get_remaining.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/apply_wrap.hpp>
namespace boost
{
@@ -32,16 +30,14 @@ namespace boost
// I need to use apply_wrap, and not apply, because apply would
// build a metafunction class from foldl<P, State, ForwardOp>
// when ForwardOp is a lambda expression.
boost::mpl::apply_wrap2<
foldl<
P,
boost::mpl::apply<
ForwardOp,
typename State::type,
typename get_result<Res>::type
>,
ForwardOp
foldl<
P,
typename ForwardOp::template apply<
typename State::type,
typename get_result<Res>::type
>,
ForwardOp
>::template apply<
typename get_remaining<Res>::type,
typename get_position<Res>::type
>
@@ -55,9 +51,9 @@ namespace boost
template <class S, class Pos>
struct apply :
boost::mpl::eval_if<
typename is_error<boost::mpl::apply<P, S, Pos> >::type,
typename is_error<typename P::template apply<S, Pos> >::type,
next_iteration<S, Pos>,
apply_unchecked<boost::mpl::apply<P, S, Pos> >
apply_unchecked<typename P::template apply<S, Pos> >
>
{};
};

View File

@@ -24,7 +24,7 @@ namespace boost
template <class S, class Pos>
struct apply :
boost::mpl::if_<
is_error<boost::mpl::apply<P, S, Pos> >,
is_error<typename P::template apply<S, Pos> >,
P,
foldl<P, State, ForwardOp>
>::type::template apply<S, Pos>

View File

@@ -13,8 +13,6 @@
#include <boost/metaparse/v1/get_remaining.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/apply_wrap.hpp>
#include <boost/mpl/equal_to.hpp>
namespace boost
@@ -32,16 +30,14 @@ namespace boost
// I need to use apply_wrap, and not apply, because apply would
// build a metafunction class from foldl<P, State, ForwardOp>
// when ForwardOp is a lambda expression.
boost::mpl::apply_wrap2<
foldl_reject_incomplete<
P,
boost::mpl::apply<
ForwardOp,
typename State::type,
typename get_result<Res>::type
>,
ForwardOp
foldl_reject_incomplete<
P,
typename ForwardOp::template apply<
typename State::type,
typename get_result<Res>::type
>,
ForwardOp
>::template apply<
typename get_remaining<Res>::type,
typename get_position<Res>::type
>
@@ -55,10 +51,10 @@ namespace boost
boost::mpl::eval_if<
typename boost::mpl::equal_to<
typename Pos::type,
typename get_position< boost::mpl::apply<P, S, Pos> >::type
typename get_position<typename P::template apply<S, Pos> >::type
>::type,
accept_state<S, Pos>,
boost::mpl::apply<P, S, Pos>
typename P::template apply<S, Pos>
>
{};
public:
@@ -67,9 +63,9 @@ namespace boost
template <class S, class Pos>
struct apply :
boost::mpl::eval_if<
typename is_error<boost::mpl::apply<P, S, Pos> >::type,
typename is_error<typename P::template apply<S, Pos> >::type,
end_of_folding<S, Pos>,
apply_unchecked<boost::mpl::apply<P, S, Pos> >
apply_unchecked<typename P::template apply<S, Pos> >
>
{};
};

View File

@@ -24,7 +24,7 @@ namespace boost
template <class S, class Pos>
struct apply :
boost::mpl::if_<
is_error<boost::mpl::apply<P, S, Pos> >,
is_error<typename P::template apply<S, Pos> >,
P,
foldl_reject_incomplete<P, State, ForwardOp>
>::type::template apply<S, Pos>

View File

@@ -13,8 +13,6 @@
#include <boost/metaparse/v1/is_error.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/apply_wrap.hpp>
namespace boost
{
@@ -28,12 +26,11 @@ namespace boost
private:
template <class Res>
struct apply_unchecked :
boost::mpl::apply_wrap2<
foldl_reject_incomplete<
P,
typename get_result<Res>::type,
ForwardOp
>,
foldl_reject_incomplete<
P,
typename get_result<Res>::type,
ForwardOp
>::template apply<
typename get_remaining<Res>::type,
typename get_position<Res>::type
>
@@ -44,9 +41,9 @@ namespace boost
template <class S, class Pos>
struct apply :
boost::mpl::eval_if<
typename is_error<boost::mpl::apply<StateP, S, Pos> >::type,
boost::mpl::apply<StateP, S, Pos>,
apply_unchecked<boost::mpl::apply<StateP, S, Pos> >
typename is_error<typename StateP::template apply<S, Pos> >::type,
typename StateP::template apply<S, Pos>,
apply_unchecked<typename StateP::template apply<S, Pos> >
>
{};
};

View File

@@ -20,8 +20,7 @@ namespace boost
private:
template <class Res>
struct apply_unchecked :
boost::mpl::apply_wrap2<
foldl<P, typename get_result<Res>::type, ForwardOp>,
foldl<P, typename get_result<Res>::type, ForwardOp>::template apply<
typename get_remaining<Res>::type,
typename get_position<Res>::type
>
@@ -32,9 +31,9 @@ namespace boost
template <class S, class Pos>
struct apply :
boost::mpl::eval_if<
typename is_error<boost::mpl::apply<StateP, S, Pos> >::type,
boost::mpl::apply<StateP, S, Pos>,
apply_unchecked<boost::mpl::apply<StateP, S, Pos> >
typename is_error<typename StateP::template apply<S, Pos> >::type,
typename StateP::template apply<S, Pos>,
apply_unchecked<typename StateP::template apply<S, Pos> >
>
{};
};

View File

@@ -24,7 +24,7 @@ namespace boost
template <class S, class Pos>
struct apply :
boost::mpl::if_<
is_error<boost::mpl::apply<P, S, Pos> >,
is_error<typename P::template apply<S, Pos> >,
P,
foldr<P, State, BackwardOp>
>::type::template apply<S, Pos>

View File

@@ -24,7 +24,7 @@ namespace boost
template <class S, class Pos>
struct apply :
boost::mpl::if_<
is_error<boost::mpl::apply<P, S, Pos> >,
is_error<typename P::template apply<S, Pos> >,
P,
foldr_reject_incomplete<P, State, BackwardOp>
>::type::template apply<S, Pos>

View File

@@ -13,8 +13,6 @@
#include <boost/metaparse/v1/get_remaining.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/apply_wrap.hpp>
namespace boost
{
@@ -29,8 +27,7 @@ namespace boost
template <class Res, class Rem>
struct apply_unchecked1 :
accept<
typename boost::mpl::apply<
BackwardOp,
typename BackwardOp::template apply<
typename get_result<Rem>::type,
typename get_result<Res>::type
>::type,
@@ -48,8 +45,7 @@ namespace boost
// build a metafunction class from
// foldr_start_with_parser<P, StateP, BackwardOp> when BackwardOp is
// a lambda expression.
boost::mpl::apply_wrap2<
foldr_start_with_parser,
typename foldr_start_with_parser::template apply<
typename get_remaining<Res>::type,
typename get_position<Res>::type
>
@@ -69,9 +65,9 @@ namespace boost
template <class S, class Pos>
struct apply :
boost::mpl::eval_if<
typename is_error<boost::mpl::apply<P, S, Pos> >::type,
boost::mpl::apply<StateP, S, Pos>,
apply_unchecked<boost::mpl::apply<P, S, Pos> >
typename is_error<typename P::template apply<S, Pos> >::type,
typename StateP::template apply<S, Pos>,
apply_unchecked<typename P::template apply<S, Pos> >
>
{};
};

View File

@@ -25,14 +25,13 @@
#include <boost/metaparse/v1/build_parser.hpp>
#include <boost/metaparse/v1/entire_input.hpp>
#include <boost/metaparse/v1/string.hpp>
#include <boost/metaparse/v1/impl/front_inserter.hpp>
#include <boost/mpl/apply_wrap.hpp>
#include <boost/mpl/at.hpp>
#include <boost/mpl/map.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/has_key.hpp>
#include <boost/mpl/lambda.hpp>
#include <boost/mpl/push_front.hpp>
#include <boost/mpl/front.hpp>
#include <boost/mpl/back.hpp>
#include <boost/mpl/pair.hpp>
@@ -64,7 +63,7 @@ namespace boost
template <class G>
struct apply :
repeated<typename boost::mpl::apply_wrap1<FState, G>::type>
repeated<typename FState::template apply<G>::type>
{};
};
@@ -75,7 +74,7 @@ namespace boost
template <class G>
struct apply :
repeated1<typename boost::mpl::apply_wrap1<FState, G>::type>
repeated1<typename FState::template apply<G>::type>
{};
};
@@ -99,8 +98,8 @@ namespace boost
template <class G>
struct apply :
sequence<
typename boost::mpl::apply_wrap1<FState, G>::type,
typename boost::mpl::apply_wrap1<FP, G>::type
typename FState::template apply<G>::type,
typename FP::template apply<G>::type
>
{};
};
@@ -121,8 +120,8 @@ namespace boost
template <class G>
struct apply :
one_of<
typename boost::mpl::apply_wrap1<FState, G>::type,
typename boost::mpl::apply_wrap1<FP, G>::type
typename FState::template apply<G>::type,
typename FP::template apply<G>::type
>
{};
};
@@ -135,10 +134,8 @@ namespace boost
struct get_parser
{
typedef
boost::mpl::apply_wrap1<
typename boost::mpl::at<typename G::rules, Name>::type,
G
>
typename boost::mpl::at<typename G::rules, Name>::type
::template apply<G>
p;
template <class Actions>
@@ -219,9 +216,7 @@ namespace boost
foldr1<
one_of<alphanum, lit_c<'_'> >,
string<>,
boost::mpl::lambda<
boost::mpl::push_front<boost::mpl::_1, boost::mpl::_2>
>::type
impl::front_inserter
>
>
name_token;
@@ -283,7 +278,7 @@ namespace boost
template <class S>
struct build_parsed_parser
{
typedef typename boost::mpl::apply_wrap1<parser_parser, S>::type p;
typedef typename parser_parser::apply<S>::type p;
typedef typename boost::mpl::front<p>::type name;
typedef typename boost::mpl::back<p>::type exp;
@@ -292,7 +287,7 @@ namespace boost
typedef the_parser type;
template <class G>
struct apply : boost::mpl::apply_wrap1<exp, G> {};
struct apply : exp::template apply<G> {};
};
typedef boost::mpl::pair<name, the_parser> type;
@@ -301,7 +296,7 @@ namespace boost
typedef build_parser<name_token> name_parser;
template <class S>
struct rebuild : boost::mpl::apply_wrap1<name_parser, S> {};
struct rebuild : name_parser::template apply<S> {};
struct no_action;
@@ -321,14 +316,10 @@ namespace boost
// Make it a parser
template <class S, class Pos>
struct apply :
boost::mpl::apply_wrap2<
typename get_parser<
grammar_builder,
typename rebuild<Start>::type
>::type,
S,
Pos
>
get_parser<
grammar_builder,
typename rebuild<Start>::type
>::type::template apply<S, Pos>
{};
template <class Name, class P>

View File

@@ -9,7 +9,6 @@
#include <boost/metaparse/v1/accept.hpp>
#include <boost/metaparse/v1/is_error.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/if.hpp>
namespace boost
@@ -27,7 +26,7 @@ namespace boost
struct apply :
accept<
typename boost::mpl::if_<
is_error<boost::mpl::apply<P, S, Pos> >,
is_error<typename P::template apply<S, Pos> >,
F,
T
>::type,

View File

@@ -12,7 +12,6 @@
#include <boost/metaparse/v1/get_position.hpp>
#include <boost/metaparse/v1/transform.hpp>
#include <boost/mpl/apply_wrap.hpp>
#include <boost/mpl/push_back.hpp>
namespace boost
@@ -35,8 +34,7 @@ namespace boost
template <class Accum, class S, class Pos, class Parser>
struct apply_unchecked :
boost::mpl::apply_wrap2<
transform<Parser,do_append<typename Accum::type> >,
transform<Parser,do_append<typename Accum::type> >::template apply<
typename S::type,
typename Pos::type
>

View File

@@ -0,0 +1,32 @@
#ifndef BOOST_METAPARSE_V1_IMPL_BACK_INSERTER_HPP
#define BOOST_METAPARSE_V1_IMPL_BACK_INSERTER_HPP
// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015.
// 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)
#include <boost/mpl/push_back.hpp>
namespace boost
{
namespace metaparse
{
namespace v1
{
namespace impl
{
struct back_inserter
{
typedef back_inserter type;
template <class T0, class T1>
struct apply : boost::mpl::push_back<T0, T1> {};
};
}
}
}
}
#endif

View File

@@ -0,0 +1,32 @@
#ifndef BOOST_METAPARSE_V1_IMPL_FRONT_INSERTER_HPP
#define BOOST_METAPARSE_V1_IMPL_FRONT_INSERTER_HPP
// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015.
// 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)
#include <boost/mpl/push_front.hpp>
namespace boost
{
namespace metaparse
{
namespace v1
{
namespace impl
{
struct front_inserter
{
typedef front_inserter type;
template <class T0, class T1>
struct apply : boost::mpl::push_front<T0, T1> {};
};
}
}
}
}
#endif

View File

@@ -13,8 +13,6 @@
#include <boost/mpl/deque.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/apply_wrap.hpp>
#include <boost/mpl/push_back.hpp>
namespace boost

View File

@@ -10,7 +10,6 @@
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/mpl/apply_wrap.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/arithmetic/dec.hpp>
@@ -47,12 +46,9 @@ namespace boost
== BOOST_PP_CAT(T, BOOST_PP_DEC(n))::type::value \
>, \
boost::mpl::false_, \
boost::mpl::apply_wrap1< \
BOOST_PP_CAT(is_any, BOOST_PP_DEC(n))< \
BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(n), T) \
>, \
C \
> \
typename BOOST_PP_CAT(is_any, BOOST_PP_DEC(n))< \
BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(n), T) \
>::template apply<C> \
> \
{}; \
};

View File

@@ -0,0 +1,33 @@
#ifndef BOOST_METAPARSE_V1_IMPL_IS_CHAR_C_HPP
#define BOOST_METAPARSE_V1_IMPL_IS_CHAR_C_HPP
// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015.
// 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)
#include <boost/mpl/bool.hpp>
namespace boost
{
namespace metaparse
{
namespace v1
{
namespace impl
{
template <char C>
struct is_char_c
{
typedef is_char_c type;
template <class Ch>
struct apply : boost::mpl::bool_<Ch::type::value == C> {};
};
}
}
}
}
#endif

View File

@@ -11,7 +11,6 @@
#include <boost/metaparse/v1/is_error.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/apply.hpp>
namespace boost
{
@@ -29,8 +28,8 @@ namespace boost
template <class S, class Pos>
struct apply :
boost::mpl::eval_if<
typename is_error<boost::mpl::apply<P, S, Pos> >::type,
boost::mpl::apply<P, S, Pos>,
typename is_error<typename P::template apply<S, Pos> >::type,
typename P::template apply<S, Pos>,
iterate_impl_unchecked<N, P, Accum, S, Pos>
>
{};

View File

@@ -11,8 +11,6 @@
#include <boost/metaparse/v1/get_remaining.hpp>
#include <boost/metaparse/v1/get_position.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/apply_wrap.hpp>
#include <boost/mpl/push_back.hpp>
namespace boost
@@ -25,17 +23,16 @@ namespace boost
{
template <int N, class P, class Accum, class S, class Pos>
struct iterate_impl_unchecked :
boost::mpl::apply_wrap2<
iterate_impl<
N - 1,
P,
typename boost::mpl::push_back<
Accum,
typename get_result<boost::mpl::apply<P, S, Pos> >::type
>::type
>,
typename get_remaining<boost::mpl::apply<P, S, Pos> >::type,
typename get_position<boost::mpl::apply<P, S, Pos> >::type
iterate_impl<
N - 1,
P,
typename boost::mpl::push_back<
Accum,
typename get_result<typename P::template apply<S, Pos> >::type
>::type
>::template apply<
typename get_remaining<typename P::template apply<S, Pos> >::type,
typename get_position<typename P::template apply<S, Pos> >::type
>
{};
}

View File

@@ -0,0 +1,36 @@
#ifndef BOOST_METAPARSE_V1_IMPL_NEXT_DIGIT_HPP
#define BOOST_METAPARSE_V1_IMPL_NEXT_DIGIT_HPP
// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015.
// 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)
#include <boost/mpl/int.hpp>
namespace boost
{
namespace metaparse
{
namespace v1
{
namespace impl
{
struct next_digit
{
typedef next_digit type;
template <class PartialResult, class NextDigit>
struct apply :
boost::mpl::int_<
PartialResult::type::value * 10 + NextDigit::type::value
>
{};
};
}
}
}
}
#endif

View File

@@ -8,8 +8,6 @@
#include <boost/metaparse/v1/impl/skip_seq.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/apply_wrap.hpp>
#include <boost/mpl/front.hpp>
#include <boost/mpl/pop_front.hpp>
#include <boost/mpl/fold.hpp>
@@ -28,11 +26,10 @@ namespace boost
private:
template <class NextResult>
struct apply_unchecked :
boost::mpl::apply_wrap2<
nth_of_c_impl<
N - 1,
typename boost::mpl::pop_front<Seq>::type
>,
nth_of_c_impl<
N - 1,
typename boost::mpl::pop_front<Seq>::type
>::template apply<
typename get_remaining<NextResult>::type,
typename get_position<NextResult>::type
>
@@ -44,11 +41,11 @@ namespace boost
struct apply :
boost::mpl::eval_if<
typename is_error<
boost::mpl::apply<typename boost::mpl::front<Seq>::type, S, Pos>
typename boost::mpl::front<Seq>::type::template apply<S, Pos>
>::type,
boost::mpl::apply<typename boost::mpl::front<Seq>::type, S, Pos>,
typename boost::mpl::front<Seq>::type::template apply<S, Pos>,
apply_unchecked<
boost::mpl::apply<typename boost::mpl::front<Seq>::type, S, Pos>
typename boost::mpl::front<Seq>::type::template apply<S, Pos>
>
>
{};
@@ -63,8 +60,7 @@ namespace boost
struct apply :
boost::mpl::fold<
typename boost::mpl::pop_front<Seq>::type,
typename boost::mpl::apply<
typename boost::mpl::front<Seq>::type,
typename boost::mpl::front<Seq>::type::template apply<
S,
Pos
>::type,

View File

@@ -12,8 +12,6 @@
#include <boost/metaparse/v1/get_position.hpp>
#include <boost/metaparse/v1/get_result.hpp>
#include <boost/mpl/apply.hpp>
namespace boost
{
namespace metaparse
@@ -38,20 +36,17 @@ namespace boost
struct apply_unchecked :
boost::mpl::eval_if<
typename is_error<
boost::mpl::apply<
P,
typename P::template apply<
typename get_remaining<Result>::type,
typename get_position<Result>::type
>
>::type,
boost::mpl::apply<
P,
typename P::template apply<
typename get_remaining<Result>::type,
typename get_position<Result>::type
>,
change_result<
boost::mpl::apply<
P,
typename P::template apply<
typename get_remaining<Result>::type,
typename get_position<Result>::type
>,

View File

@@ -8,10 +8,7 @@
#include <boost/metaparse/v1/digit_val.hpp>
#include <boost/metaparse/v1/foldl1.hpp>
#include <boost/mpl/lambda.hpp>
#include <boost/mpl/times.hpp>
#include <boost/mpl/plus.hpp>
#include <boost/metaparse/v1/impl/next_digit.hpp>
namespace boost
{
@@ -19,20 +16,7 @@ namespace boost
{
namespace v1
{
typedef
foldl1<
digit_val,
boost::mpl::int_<0>,
// I need to wrap it with lambda, because int_ may be used
// in an apply and turned into a lambda expression too early.
boost::mpl::lambda<
boost::mpl::plus<
boost::mpl::times<boost::mpl::_1, boost::mpl::int_<10> >,
boost::mpl::_2
>
>::type
>
int_;
typedef foldl1<digit_val, boost::mpl::int_<0>, impl::next_digit> int_;
}
}
}

View File

@@ -18,7 +18,6 @@
#include <boost/mpl/empty.hpp>
#include <boost/mpl/pop_front.hpp>
#include <boost/mpl/front.hpp>
#include <boost/mpl/apply_wrap.hpp>
namespace boost
{
@@ -42,13 +41,12 @@ namespace boost
template <class S, class Pos>
struct apply_unchecked :
boost::mpl::apply_wrap2<
rest_parser,
rest_parser::template apply<
typename get_remaining<
boost::mpl::apply_wrap2<next_char_parser, S, Pos>
typename next_char_parser::template apply<S, Pos>
>::type,
typename get_position<
boost::mpl::apply_wrap2<next_char_parser, S, Pos>
typename next_char_parser::template apply<S, Pos>
>::type
>
{};
@@ -57,9 +55,9 @@ namespace boost
struct apply :
boost::mpl::eval_if<
typename is_error<
boost::mpl::apply_wrap2<next_char_parser, S, Pos>
typename next_char_parser::template apply<S, Pos>
>::type,
boost::mpl::apply_wrap2<next_char_parser, S, Pos>,
typename next_char_parser::template apply<S, Pos>,
apply_unchecked<S, Pos>
>
{};
@@ -69,15 +67,11 @@ namespace boost
template <class S, class Pos>
struct apply :
boost::mpl::apply_wrap2<
typename boost::mpl::if_<
boost::mpl::empty<Kw>,
return_<ResultType>,
nonempty
>::type,
S,
Pos
>
boost::mpl::if_<
boost::mpl::empty<Kw>,
return_<ResultType>,
nonempty
>::type::template apply<S, Pos>
{};
};
}

View File

@@ -6,17 +6,11 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/mpl/char.hpp>
#include <boost/metaparse/v1/error/literal_expected.hpp>
#include <boost/metaparse/v1/accept_when.hpp>
#include <boost/metaparse/v1/one_char.hpp>
#include <boost/metaparse/v1/change_error_message.hpp>
#include <boost/mpl/equal_to.hpp>
#include <boost/mpl/lambda.hpp>
#include <boost/mpl/char.hpp>
#include <boost/metaparse/v1/impl/is_char_c.hpp>
namespace boost
{
@@ -28,9 +22,7 @@ namespace boost
struct lit_c :
accept_when<
change_error_message<one_char, error::literal_expected<C> >,
typename boost::mpl::lambda<
boost::mpl::equal_to<boost::mpl::_1, boost::mpl::char_<C> >
>::type,
impl::is_char_c<C>,
error::literal_expected<C>
>
{};

View File

@@ -10,7 +10,6 @@
#include <boost/metaparse/v1/accept.hpp>
#include <boost/metaparse/v1/get_result.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/eval_if.hpp>
namespace boost
@@ -26,7 +25,7 @@ namespace boost
template <class S, class Pos>
struct no_error :
accept<
typename get_result<boost::mpl::apply<P, S, Pos> >::type,
typename get_result<typename P::template apply<S, Pos> >::type,
S,
Pos
>
@@ -37,8 +36,8 @@ namespace boost
template <class S, class Pos>
struct apply :
boost::mpl::eval_if<
typename is_error<boost::mpl::apply<P, S, Pos> >::type,
boost::mpl::apply<P, S, Pos>,
typename is_error<typename P::template apply<S, Pos> >::type,
typename P::template apply<S, Pos>,
no_error<S, Pos>
>
{};

View File

@@ -8,7 +8,6 @@
#include <boost/metaparse/v1/fwd/next_char.hpp>
#include <boost/mpl/apply_wrap.hpp>
#include <boost/mpl/tag.hpp>
namespace boost
@@ -19,11 +18,9 @@ namespace boost
{
template <class P, class Ch>
struct next_char :
boost::mpl::apply_wrap2<
next_char_impl<typename boost::mpl::tag<typename P::type>::type>,
typename P::type,
typename Ch::type
>
next_char_impl<
typename boost::mpl::tag<typename P::type>::type
>::template apply<typename P::type, typename Ch::type>
{};
}
}

View File

@@ -8,7 +8,6 @@
#include <boost/metaparse/v1/fwd/next_line.hpp>
#include <boost/mpl/apply_wrap.hpp>
#include <boost/mpl/tag.hpp>
namespace boost
@@ -19,11 +18,9 @@ namespace boost
{
template <class P, class Ch>
struct next_line :
boost::mpl::apply_wrap2<
next_line_impl<typename boost::mpl::tag<typename P::type>::type>,
typename P::type,
typename Ch::type
>
next_line_impl<
typename boost::mpl::tag<typename P::type>::type
>::template apply<typename P::type, typename Ch::type>
{};
}
}

View File

@@ -9,7 +9,6 @@
#include <boost/metaparse/v1/is_error.hpp>
#include <boost/metaparse/v1/accept.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/if.hpp>
namespace boost
@@ -26,10 +25,10 @@ namespace boost
template <class S, class Pos>
struct apply :
boost::mpl::if_<
is_error<boost::mpl::apply<P, S, Pos> >,
is_error<typename P::template apply<S, Pos> >,
accept<Default, S, Pos>,
// is_error evaluates it anyway
typename boost::mpl::apply<P, S, Pos>::type
typename P::template apply<S, Pos>::type
>
{};
};

View File

@@ -7,10 +7,9 @@
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/metaparse/v1/foldl.hpp>
#include <boost/metaparse/v1/impl/back_inserter.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/mpl/lambda.hpp>
namespace boost
{
@@ -19,15 +18,7 @@ namespace boost
namespace v1
{
template <class P>
struct repeated :
foldl<
P,
boost::mpl::vector<>,
typename boost::mpl::lambda<
boost::mpl::push_back<boost::mpl::_1, boost::mpl::_2>
>::type
>
{};
struct repeated : foldl<P, boost::mpl::vector<>, impl::back_inserter> {};
}
}
}

View File

@@ -7,10 +7,9 @@
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/metaparse/v1/foldl1.hpp>
#include <boost/metaparse/v1/impl/back_inserter.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/mpl/lambda.hpp>
namespace boost
{
@@ -20,13 +19,7 @@ namespace boost
{
template <class P>
struct repeated1 :
foldl1<
P,
boost::mpl::vector<>,
boost::mpl::lambda<
boost::mpl::push_back<boost::mpl::_1, boost::mpl::_2>
>::type
>
foldl1<P, boost::mpl::vector<>, impl::back_inserter>
{};
}
}

View File

@@ -7,10 +7,9 @@
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/metaparse/v1/foldl_reject_incomplete.hpp>
#include <boost/metaparse/v1/impl/back_inserter.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/mpl/lambda.hpp>
namespace boost
{
@@ -20,13 +19,7 @@ namespace boost
{
template <class P>
struct repeated_reject_incomplete :
foldl_reject_incomplete<
P,
boost::mpl::vector<>,
typename boost::mpl::lambda<
boost::mpl::push_back<boost::mpl::_1, boost::mpl::_2>
>::type
>
foldl_reject_incomplete<P, boost::mpl::vector<>, impl::back_inserter>
{};
}
}

View File

@@ -7,10 +7,9 @@
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/metaparse/v1/foldl_reject_incomplete1.hpp>
#include <boost/metaparse/v1/impl/back_inserter.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/mpl/lambda.hpp>
namespace boost
{
@@ -20,13 +19,7 @@ namespace boost
{
template <class P>
struct repeated_reject_incomplete1 :
foldl_reject_incomplete1<
P,
boost::mpl::vector<>,
boost::mpl::lambda<
boost::mpl::push_back<boost::mpl::_1, boost::mpl::_2>
>::type
>
foldl_reject_incomplete1<P, boost::mpl::vector<>, impl::back_inserter>
{};
}
}

View File

@@ -6,8 +6,6 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/mpl/apply.hpp>
namespace boost
{
namespace metaparse
@@ -20,7 +18,7 @@ namespace boost
typedef swap type;
template <class A, class B>
struct apply : boost::mpl::apply<F, B, A> {};
struct apply : F::template apply<B, A> {};
};
}
}

View File

@@ -13,7 +13,6 @@
#include <boost/metaparse/v1/unless_error.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/apply.hpp>
namespace boost
{
@@ -28,12 +27,11 @@ namespace boost
template <class S, class Pos>
struct no_error :
accept<
typename boost::mpl::apply<
T,
typename get_result<boost::mpl::apply<P, S, Pos> >::type
typename T::template apply<
typename get_result<typename P::template apply<S, Pos> >::type
>::type,
get_remaining<boost::mpl::apply<P, S, Pos> >,
get_position<boost::mpl::apply<P, S, Pos> >
get_remaining<typename P::template apply<S, Pos> >,
get_position<typename P::template apply<S, Pos> >
>
{};
public:
@@ -41,7 +39,7 @@ namespace boost
template <class S, class Pos>
struct apply :
unless_error<boost::mpl::apply<P, S, Pos>, no_error<S, Pos> >
unless_error<typename P::template apply<S, Pos>, no_error<S, Pos> >
{};
};
}

View File

@@ -8,7 +8,6 @@
#include <boost/metaparse/v1/is_error.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/eval_if.hpp>
namespace boost
@@ -23,9 +22,11 @@ namespace boost
template <class S, class Pos>
struct apply :
boost::mpl::eval_if<
typename is_error<boost::mpl::apply<P, S, Pos> >::type,
boost::mpl::apply<F, typename boost::mpl::apply<P, S, Pos>::type>,
boost::mpl::apply<P, S, Pos>
typename is_error<typename P::template apply<S, Pos> >::type,
typename F::template apply<
typename P::template apply<S, Pos>::type
>,
typename P::template apply<S, Pos>
>
{};

View File

@@ -11,7 +11,6 @@
#include <boost/metaparse/v1/get_position.hpp>
#include <boost/metaparse/v1/get_message.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/eval_if.hpp>
namespace boost
@@ -26,7 +25,7 @@ namespace boost
template <class R>
struct rejection :
reject<
typename boost::mpl::apply<F, typename get_message<R>::type>::type,
typename F::template apply<typename get_message<R>::type>::type,
get_position<R>
>
{};
@@ -34,9 +33,9 @@ namespace boost
template <class S, class Pos>
struct apply :
boost::mpl::eval_if<
typename is_error<boost::mpl::apply<P, S, Pos> >::type,
rejection<boost::mpl::apply<P, S, Pos> >,
boost::mpl::apply<P, S, Pos>
typename is_error<typename P::template apply<S, Pos> >::type,
rejection<typename P::template apply<S, Pos> >,
typename P::template apply<S, Pos>
>
{};

View File

@@ -8,7 +8,6 @@
#include <boost/mpl/less_equal.hpp>
#include <boost/mpl/comparison.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/quote.hpp>
#include <boost/mpl/bool.hpp>

View File

@@ -9,6 +9,7 @@ project metaparse :
test-suite metaparse-unit-tests :
[ compile accept.cpp ]
[ compile accept_when.cpp ]
[ compile back_inserter.cpp ]
[ compile all_headers.cpp ]
[ compile alphanum.cpp ]
[ compile always_c.cpp ]
@@ -40,6 +41,7 @@ test-suite metaparse-unit-tests :
[ compile foldr_reject_incomplete1.cpp ]
[ compile foldr_reject_incomplete.cpp ]
[ compile foldr_start_with_parser.cpp ]
[ compile front_inserter.cpp ]
[ compile grammar.cpp ]
[ compile has_type.cpp ]
[ compile if_.cpp ]
@@ -47,6 +49,7 @@ test-suite metaparse-unit-tests :
[ compile in_range.cpp ]
[ compile int_.cpp ]
[ compile int_to_digit.cpp ]
[ compile is_char_c.cpp ]
[ compile is_digit.cpp ]
[ compile is_error.cpp ]
[ compile is_lcase_letter.cpp ]
@@ -62,6 +65,7 @@ test-suite metaparse-unit-tests :
[ compile lit.cpp ]
[ compile look_ahead.cpp ]
[ compile middle_of.cpp ]
[ compile next_digit.cpp ]
[ compile nth_of.cpp ]
[ compile one_char.cpp ]
[ compile one_char_except_c.cpp ]

26
test/back_inserter.cpp Normal file
View File

@@ -0,0 +1,26 @@
// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015.
// 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)
#include <boost/metaparse/v1/impl/back_inserter.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/equal.hpp>
#include <boost/mpl/deque.hpp>
#include "test_case.hpp"
BOOST_METAPARSE_TEST_CASE(back_inserter)
{
using boost::metaparse::v1::impl::back_inserter;
using boost::mpl::equal;
using boost::mpl::deque;
// test_inserts_at_the_back
BOOST_MPL_ASSERT((
equal<deque<int, char>, back_inserter::apply<deque<int>, char>::type>
));
}

View File

@@ -4,23 +4,19 @@
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/metaparse/foldl.hpp>
#include <boost/metaparse/v1/impl/back_inserter.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/mpl/lambda.hpp>
using boost::metaparse::foldl;
using boost::metaparse::v1::impl::back_inserter;
using boost::mpl::vector;
using boost::mpl::push_back;
using boost::mpl::_1;
using boost::mpl::_2;
using boost::mpl::lambda;
namespace
{
template <class P>
struct repeated : foldl<P, vector<>, lambda<push_back<_1, _2> >::type> {};
struct repeated : foldl<P, vector<>, back_inserter> {};
}
#define TEST_NAME foldl

View File

@@ -4,22 +4,19 @@
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/metaparse/foldl1.hpp>
#include <boost/metaparse/v1/impl/back_inserter.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/mpl/lambda.hpp>
using boost::metaparse::foldl1;
using boost::metaparse::v1::impl::back_inserter;
using boost::mpl::vector;
using boost::mpl::push_back;
using boost::mpl::_1;
using boost::mpl::_2;
namespace
{
template <class P>
struct repeated1 : foldl1<P, vector<>, push_back<_1, _2> > {};
struct repeated1 : foldl1<P, vector<>, back_inserter> {};
}
#define TEST_NAME foldl1

View File

@@ -4,24 +4,20 @@
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/metaparse/foldl_reject_incomplete.hpp>
#include <boost/metaparse/v1/impl/back_inserter.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/mpl/lambda.hpp>
using boost::metaparse::foldl_reject_incomplete;
using boost::metaparse::v1::impl::back_inserter;
using boost::mpl::vector;
using boost::mpl::push_back;
using boost::mpl::_1;
using boost::mpl::_2;
using boost::mpl::lambda;
namespace
{
template <class P>
struct repeated_reject_incomplete :
foldl_reject_incomplete<P, vector<>, lambda<push_back<_1, _2> >::type>
foldl_reject_incomplete<P, vector<>, back_inserter>
{};
}

View File

@@ -4,23 +4,20 @@
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/metaparse/foldl_reject_incomplete1.hpp>
#include <boost/metaparse/v1/impl/back_inserter.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/mpl/lambda.hpp>
using boost::metaparse::foldl_reject_incomplete1;
using boost::metaparse::v1::impl::back_inserter;
using boost::mpl::vector;
using boost::mpl::push_back;
using boost::mpl::_1;
using boost::mpl::_2;
namespace
{
template <class P>
struct repeated_reject_incomplete1 :
foldl_reject_incomplete1<P, vector<>, push_back<_1, _2> >
foldl_reject_incomplete1<P, vector<>, back_inserter>
{};
}

View File

@@ -10,6 +10,7 @@
#include <boost/metaparse/get_result.hpp>
#include <boost/metaparse/return_.hpp>
#include <boost/metaparse/sequence.hpp>
#include <boost/metaparse/v1/impl/back_inserter.hpp>
#include "common.hpp"
@@ -73,12 +74,9 @@ BOOST_METAPARSE_TEST_CASE(foldl_reject_incomplete_start_with_parser)
using boost::metaparse::foldl_reject_incomplete_start_with_parser;
using boost::metaparse::return_;
using boost::metaparse::v1::impl::back_inserter;
using boost::mpl::vector;
using boost::mpl::push_back;
using boost::mpl::_1;
using boost::mpl::_2;
using boost::mpl::lambda;
namespace
{
@@ -87,7 +85,7 @@ namespace
foldl_reject_incomplete_start_with_parser<
P,
return_<vector<> >,
lambda<push_back<_1, _2> >::type
back_inserter
>
{};
}

View File

@@ -9,13 +9,13 @@
#include <boost/metaparse/is_error.hpp>
#include <boost/metaparse/get_result.hpp>
#include <boost/metaparse/return_.hpp>
#include <boost/metaparse/v1/impl/back_inserter.hpp>
#include "common.hpp"
#include <boost/mpl/apply_wrap.hpp>
#include <boost/mpl/char.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/push_back.hpp>
#include "test_case.hpp"
@@ -70,22 +70,15 @@ BOOST_METAPARSE_TEST_CASE(foldl_start_with_parser)
using boost::metaparse::foldl_start_with_parser;
using boost::metaparse::return_;
using boost::metaparse::v1::impl::back_inserter;
using boost::mpl::vector;
using boost::mpl::push_back;
using boost::mpl::_1;
using boost::mpl::_2;
using boost::mpl::lambda;
namespace
{
template <class P>
struct repeated :
foldl_start_with_parser<
P,
return_<vector<> >,
lambda<push_back<_1, _2> >::type
>
foldl_start_with_parser<P, return_<vector<> >, back_inserter>
{};
}

View File

@@ -4,23 +4,19 @@
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/metaparse/foldr.hpp>
#include <boost/metaparse/v1/impl/front_inserter.hpp>
#include <boost/mpl/list.hpp>
#include <boost/mpl/push_front.hpp>
#include <boost/mpl/lambda.hpp>
using boost::metaparse::foldr;
using boost::metaparse::v1::impl::front_inserter;
using boost::mpl::list;
using boost::mpl::push_front;
using boost::mpl::_1;
using boost::mpl::_2;
using boost::mpl::lambda;
namespace
{
template <class P>
struct repeated : foldr<P, list<>, lambda<push_front<_1, _2> >::type> {};
struct repeated : foldr<P, list<>, front_inserter> {};
}
#define TEST_NAME foldr

View File

@@ -4,22 +4,19 @@
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/metaparse/foldr1.hpp>
#include <boost/metaparse/v1/impl/front_inserter.hpp>
#include <boost/mpl/list.hpp>
#include <boost/mpl/push_front.hpp>
#include <boost/mpl/lambda.hpp>
using boost::metaparse::foldr1;
using boost::metaparse::v1::impl::front_inserter;
using boost::mpl::list;
using boost::mpl::push_front;
using boost::mpl::_1;
using boost::mpl::_2;
namespace
{
template <class P>
struct repeated1 : foldr1<P, list<>, push_front<_1, _2> > {};
struct repeated1 : foldr1<P, list<>, front_inserter> {};
}
#define TEST_NAME foldr1

View File

@@ -4,24 +4,20 @@
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/metaparse/foldr_reject_incomplete.hpp>
#include <boost/metaparse/v1/impl/front_inserter.hpp>
#include <boost/mpl/list.hpp>
#include <boost/mpl/push_front.hpp>
#include <boost/mpl/lambda.hpp>
using boost::metaparse::foldr_reject_incomplete;
using boost::metaparse::v1::impl::front_inserter;
using boost::mpl::list;
using boost::mpl::push_front;
using boost::mpl::_1;
using boost::mpl::_2;
using boost::mpl::lambda;
namespace
{
template <class P>
struct repeated_reject_incomplete :
foldr_reject_incomplete<P, list<>, lambda<push_front<_1, _2> >::type>
foldr_reject_incomplete<P, list<>, front_inserter>
{};
}

View File

@@ -4,23 +4,20 @@
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/metaparse/foldr_reject_incomplete1.hpp>
#include <boost/metaparse/v1/impl/front_inserter.hpp>
#include <boost/mpl/list.hpp>
#include <boost/mpl/push_front.hpp>
#include <boost/mpl/lambda.hpp>
using boost::metaparse::foldr_reject_incomplete1;
using boost::metaparse::v1::impl::front_inserter;
using boost::mpl::list;
using boost::mpl::push_front;
using boost::mpl::_1;
using boost::mpl::_2;
namespace
{
template <class P>
struct repeated_reject_incomplete1 :
foldr_reject_incomplete1<P, list<>, push_front<_1, _2> >
foldr_reject_incomplete1<P, list<>, front_inserter>
{};
}

26
test/front_inserter.cpp Normal file
View File

@@ -0,0 +1,26 @@
// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015.
// 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)
#include <boost/metaparse/v1/impl/front_inserter.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/equal.hpp>
#include <boost/mpl/deque.hpp>
#include "test_case.hpp"
BOOST_METAPARSE_TEST_CASE(front_inserter)
{
using boost::metaparse::v1::impl::front_inserter;
using boost::mpl::equal;
using boost::mpl::deque;
// test_inserts_at_the_front
BOOST_MPL_ASSERT((
equal<deque<int, char>, front_inserter::apply<deque<char>, int>::type>
));
}

25
test/is_char_c.cpp Normal file
View File

@@ -0,0 +1,25 @@
// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015.
// 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)
#include <boost/metaparse/v1/impl/is_char_c.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/char.hpp>
#include "test_case.hpp"
BOOST_METAPARSE_TEST_CASE(is_char_c)
{
using boost::metaparse::v1::impl::is_char_c;
using boost::mpl::char_;
// test_for_the_same_char
BOOST_MPL_ASSERT(( is_char_c<'x'>::apply<char_<'x'> > ));
// test_for_another_char
BOOST_MPL_ASSERT_NOT(( is_char_c<'x'>::apply<char_<'y'> > ));
}

25
test/next_digit.cpp Normal file
View File

@@ -0,0 +1,25 @@
// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015.
// 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)
#include <boost/metaparse/v1/impl/next_digit.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/equal_to.hpp>
#include <boost/mpl/int.hpp>
#include "test_case.hpp"
BOOST_METAPARSE_TEST_CASE(next_digit)
{
using boost::metaparse::v1::impl::next_digit;
using boost::mpl::equal_to;
using boost::mpl::int_;
BOOST_MPL_ASSERT((equal_to<int_< 0>, next_digit::apply<int_<0>, int_<0> > >));
BOOST_MPL_ASSERT((equal_to<int_<10>, next_digit::apply<int_<1>, int_<0> > >));
BOOST_MPL_ASSERT((equal_to<int_<13>, next_digit::apply<int_<1>, int_<3> > >));
}

View File

@@ -7,6 +7,8 @@
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/assert.hpp>
#include "test_case.hpp"
namespace

View File

@@ -16,7 +16,6 @@
#include <boost/mpl/always.hpp>
#include <boost/mpl/apply_wrap.hpp>
#include <boost/mpl/front.hpp>
#include <boost/mpl/lambda.hpp>
#include <boost/mpl/assert.hpp>
#include "test_case.hpp"
@@ -30,6 +29,14 @@ namespace
typedef always<char_x> f;
typedef repeated<one_char> repeated_one_char;
struct get_front
{
typedef get_front type;
template <class C>
struct apply : boost::mpl::front<C> {};
};
}
BOOST_METAPARSE_TEST_CASE(transform)
@@ -41,8 +48,6 @@ BOOST_METAPARSE_TEST_CASE(transform)
using boost::mpl::equal_to;
using boost::mpl::apply_wrap2;
using boost::mpl::front;
using boost::mpl::_1;
// test_normal_case
BOOST_MPL_ASSERT((
@@ -64,7 +69,7 @@ BOOST_METAPARSE_TEST_CASE(transform)
BOOST_MPL_ASSERT((
equal_to<
get_result<
apply_wrap2<transform<repeated_one_char, front<_1> >, str_hello, start>
apply_wrap2<transform<repeated_one_char, get_front>, str_hello, start>
>::type,
char_h
>