mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
SPROUT_CONFIG_SUPPORT_TEMPORARY_CONTAINER_ITERATION をデフォルトで有効に変更
sprout/type/string.hpp 追加
This commit is contained in:
parent
86073fea83
commit
231910c863
43 changed files with 4816 additions and 16 deletions
393
sprout/breed/transform/call.hpp
Normal file
393
sprout/breed/transform/call.hpp
Normal file
|
@ -0,0 +1,393 @@
|
|||
#ifndef SPROUT_BREED_TRANSFORM_CALL_HPP
|
||||
#define SPROUT_BREED_TRANSFORM_CALL_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/utility/pack.hpp>
|
||||
#include <sprout/type/type_tuple.hpp>
|
||||
#include <sprout/breed/breed_fwd.hpp>
|
||||
#include <sprout/breed/traits.hpp>
|
||||
#include <sprout/breed/transform/impl.hpp>
|
||||
#include <sprout/breed/detail/std_result_of.hpp>
|
||||
#include <sprout/breed/detail/as_lvalue.hpp>
|
||||
#include <sprout/breed/detail/poly_function.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace breed {
|
||||
//
|
||||
// call
|
||||
//
|
||||
template<typename PrimitiveTransform>
|
||||
struct call
|
||||
: public PrimitiveTransform
|
||||
{};
|
||||
template<typename Fun>
|
||||
struct call<Fun()>
|
||||
: public sprout::breed::transform<sprout::breed::call<Fun()> >
|
||||
{
|
||||
public:
|
||||
template<typename Expr, typename State, typename Data, bool B>
|
||||
struct impl2
|
||||
: public sprout::breed::transform_impl<Expr, State, Data>
|
||||
{
|
||||
public:
|
||||
typedef typename sprout::breed::detail::std_result_of<Fun()>::type result_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR result_type operator()(
|
||||
typename impl2::expr_param,
|
||||
typename impl2::state_param,
|
||||
typename impl2::data_param
|
||||
) const
|
||||
{
|
||||
return Fun()();
|
||||
}
|
||||
};
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl2<Expr, State, Data, true>
|
||||
: public Fun::template impl<Expr, State, Data>
|
||||
{};
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl
|
||||
: public impl2<Expr, State, Data, sprout::breed::detail::is_transform_<Fun>::value>
|
||||
{};
|
||||
};
|
||||
template<typename Fun, typename A0>
|
||||
struct call<Fun(A0)>
|
||||
: public sprout::breed::transform<sprout::breed::call<Fun(A0)> >
|
||||
{
|
||||
public:
|
||||
template<typename Expr, typename State, typename Data, bool B>
|
||||
struct impl2
|
||||
: public sprout::breed::transform_impl<Expr, State, Data>
|
||||
{
|
||||
private:
|
||||
template<typename A>
|
||||
struct a_ {
|
||||
public:
|
||||
typedef typename sprout::breed::when<sprout::breed::_, A>::template impl<
|
||||
Expr,
|
||||
State,
|
||||
Data
|
||||
> type;
|
||||
};
|
||||
template<typename... Args>
|
||||
struct fun_ {
|
||||
public:
|
||||
typedef Fun type(typename a_<Args>::type::result_type...);
|
||||
};
|
||||
template<typename... Args>
|
||||
struct function_
|
||||
: public sprout::breed::detail::poly_function_traits<
|
||||
Fun,
|
||||
typename fun_<Args...>::type
|
||||
>
|
||||
{};
|
||||
public:
|
||||
template<long N>
|
||||
struct a {
|
||||
public:
|
||||
typedef typename a_<typename sprout::tppack_at<N, A0>::type>::type::result_type type;
|
||||
};
|
||||
typedef function_<A0> function_traits;
|
||||
typedef typename function_traits::result_type result_type;
|
||||
SPROUT_CONSTEXPR result_type operator ()(
|
||||
typename impl2::expr_param e,
|
||||
typename impl2::state_param s,
|
||||
typename impl2::data_param d
|
||||
) const
|
||||
{
|
||||
return typename function_traits::function_type()(
|
||||
sprout::breed::detail::as_lvalue(a_<A0>()(e, s, d))
|
||||
);
|
||||
}
|
||||
};
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl2<Expr, State, Data, true>
|
||||
: public sprout::breed::transform_impl<Expr, State, Data>
|
||||
{
|
||||
private:
|
||||
template<typename A>
|
||||
struct a_ {
|
||||
public:
|
||||
typedef typename sprout::breed::when<sprout::breed::_, A>::template impl<
|
||||
Expr,
|
||||
State,
|
||||
Data
|
||||
> type;
|
||||
};
|
||||
typedef Fun::template impl<typename a_<A0>::type, State, Data> function_;
|
||||
public:
|
||||
template<long N>
|
||||
struct a {
|
||||
public:
|
||||
typedef typename a_<typename sprout::tppack_at<N, A0>::type>::type::result_type type;
|
||||
};
|
||||
typedef template function_::result_type result_type;
|
||||
SPROUT_CONSTEXPR result_type operator ()(
|
||||
typename impl2::expr_param e,
|
||||
typename impl2::state_param s,
|
||||
typename impl2::data_param d
|
||||
) const
|
||||
{
|
||||
return function_()(
|
||||
typename a_<A0>::type()(e, s, d),
|
||||
s,
|
||||
d
|
||||
);
|
||||
}
|
||||
};
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl
|
||||
: public impl2<Expr, State, Data, sprout::breed::detail::is_transform_<Fun>::value>
|
||||
{};
|
||||
};
|
||||
template<typename Fun, typename A0, typename A1>
|
||||
struct call<Fun(A0, A1)>
|
||||
: public sprout::breed::transform<sprout::breed::call<Fun(A0, A1)> >
|
||||
{
|
||||
public:
|
||||
template<typename Expr, typename State, typename Data, bool B>
|
||||
struct impl2
|
||||
: public sprout::breed::transform_impl<Expr, State, Data>
|
||||
{
|
||||
private:
|
||||
template<typename A>
|
||||
struct a_ {
|
||||
public:
|
||||
typedef typename sprout::breed::when<sprout::breed::_, A>::template impl<
|
||||
Expr,
|
||||
State,
|
||||
Data
|
||||
> type;
|
||||
};
|
||||
template<typename... Args>
|
||||
struct fun_ {
|
||||
public:
|
||||
typedef Fun type(typename a_<Args>::type::result_type...);
|
||||
};
|
||||
template<typename... Args>
|
||||
struct function_
|
||||
: public sprout::breed::detail::poly_function_traits<
|
||||
Fun,
|
||||
typename fun_<Args...>::type
|
||||
>
|
||||
{};
|
||||
public:
|
||||
template<long N>
|
||||
struct a {
|
||||
public:
|
||||
typedef typename a_<typename sprout::tppack_at<N, A0, A1>::type>::type::result_type type;
|
||||
};
|
||||
typedef function_<A0, A1> function_traits;
|
||||
typedef typename function_traits::result_type result_type;
|
||||
SPROUT_CONSTEXPR result_type operator ()(
|
||||
typename impl2::expr_param e,
|
||||
typename impl2::state_param s,
|
||||
typename impl2::data_param d
|
||||
) const
|
||||
{
|
||||
return typename function_traits::function_type()(
|
||||
sprout::breed::detail::as_lvalue(a_<A0>()(e, s, d)),
|
||||
sprout::breed::detail::as_lvalue(a_<A1>()(e, s, d))
|
||||
);
|
||||
}
|
||||
};
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl2<Expr, State, Data, true>
|
||||
: public sprout::breed::transform_impl<Expr, State, Data>
|
||||
{
|
||||
private:
|
||||
template<typename A>
|
||||
struct a_ {
|
||||
public:
|
||||
typedef typename sprout::breed::when<sprout::breed::_, A>::template impl<
|
||||
Expr,
|
||||
State,
|
||||
Data
|
||||
> type;
|
||||
};
|
||||
typedef Fun::template impl<typename a_<A0>::type, typename a_<A1>::type, Data> function_;
|
||||
public:
|
||||
template<long N>
|
||||
struct a {
|
||||
public:
|
||||
typedef typename a_<typename sprout::tppack_at<N, A0, A1>::type>::type::result_type type;
|
||||
};
|
||||
typedef template function_::result_type result_type;
|
||||
SPROUT_CONSTEXPR result_type operator ()(
|
||||
typename impl2::expr_param e,
|
||||
typename impl2::state_param s,
|
||||
typename impl2::data_param d
|
||||
) const
|
||||
{
|
||||
return function_()(
|
||||
typename a_<A0>::type()(e, s, d),
|
||||
typename a_<A1>::type()(e, s, d),
|
||||
d
|
||||
);
|
||||
}
|
||||
};
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl
|
||||
: public impl2<Expr, State, Data, sprout::breed::detail::is_transform_<Fun>::value>
|
||||
{};
|
||||
};
|
||||
template<typename Fun, typename A0, typename A1, typename A2>
|
||||
struct call<Fun(A0, A1, A2)>
|
||||
: public sprout::breed::transform<sprout::breed::call<Fun(A0, A1, A2)> >
|
||||
{
|
||||
public:
|
||||
template<typename Expr, typename State, typename Data, bool B>
|
||||
struct impl2
|
||||
: public sprout::breed::transform_impl<Expr, State, Data>
|
||||
{
|
||||
private:
|
||||
template<typename A>
|
||||
struct a_ {
|
||||
public:
|
||||
typedef typename sprout::breed::when<sprout::breed::_, A>::template impl<
|
||||
Expr,
|
||||
State,
|
||||
Data
|
||||
> type;
|
||||
};
|
||||
template<typename... Args>
|
||||
struct fun_ {
|
||||
public:
|
||||
typedef Fun type(typename a_<Args>::type::result_type...);
|
||||
};
|
||||
template<typename... Args>
|
||||
struct function_
|
||||
: public sprout::breed::detail::poly_function_traits<
|
||||
Fun,
|
||||
typename fun_<Args...>::type
|
||||
>
|
||||
{};
|
||||
public:
|
||||
template<long N>
|
||||
struct a {
|
||||
public:
|
||||
typedef typename a_<typename sprout::tppack_at<N, A0, A1, A2>::type>::type::result_type type;
|
||||
};
|
||||
typedef function_<A0, A1, A2> function_traits;
|
||||
typedef typename function_traits::result_type result_type;
|
||||
SPROUT_CONSTEXPR result_type operator ()(
|
||||
typename impl2::expr_param e,
|
||||
typename impl2::state_param s,
|
||||
typename impl2::data_param d
|
||||
) const
|
||||
{
|
||||
return typename function_traits::function_type()(
|
||||
sprout::breed::detail::as_lvalue(a_<A0>()(e, s, d)),
|
||||
sprout::breed::detail::as_lvalue(a_<A1>()(e, s, d)),
|
||||
sprout::breed::detail::as_lvalue(a_<A2>()(e, s, d))
|
||||
);
|
||||
}
|
||||
};
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl2<Expr, State, Data, true>
|
||||
: public sprout::breed::transform_impl<Expr, State, Data>
|
||||
{
|
||||
private:
|
||||
template<typename A>
|
||||
struct a_ {
|
||||
public:
|
||||
typedef typename sprout::breed::when<sprout::breed::_, A>::template impl<
|
||||
Expr,
|
||||
State,
|
||||
Data
|
||||
> type;
|
||||
};
|
||||
typedef Fun::template impl<typename a_<A0>::type, typename a_<A1>::type, typename a_<A2>::type> function_;
|
||||
public:
|
||||
template<long N>
|
||||
struct a {
|
||||
public:
|
||||
typedef typename a_<typename sprout::tppack_at<N, A0, A1, A2>::type>::type::result_type type;
|
||||
};
|
||||
typedef template function_::result_type result_type;
|
||||
SPROUT_CONSTEXPR result_type operator ()(
|
||||
typename impl2::expr_param e,
|
||||
typename impl2::state_param s,
|
||||
typename impl2::data_param d
|
||||
) const
|
||||
{
|
||||
return function_()(
|
||||
typename a_<A0>::type()(e, s, d),
|
||||
typename a_<A1>::type()(e, s, d),
|
||||
typename a_<A2>::type()(e, s, d)
|
||||
);
|
||||
}
|
||||
};
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl
|
||||
: public impl2<Expr, State, Data, sprout::breed::detail::is_transform_<Fun>::value>
|
||||
{};
|
||||
};
|
||||
template<typename Fun, typename... Args>
|
||||
struct call<Fun(Args...)>
|
||||
: public sprout::breed::transform<sprout::breed::call<Fun(Args...)> >
|
||||
{
|
||||
public:
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl
|
||||
: public sprout::breed::transform_impl<Expr, State, Data>
|
||||
{
|
||||
private:
|
||||
template<typename A>
|
||||
struct a_ {
|
||||
public:
|
||||
typedef typename sprout::breed::when<sprout::breed::_, A>::template impl<
|
||||
Expr,
|
||||
State,
|
||||
Data
|
||||
> type;
|
||||
};
|
||||
template<typename... Args>
|
||||
struct fun_ {
|
||||
public:
|
||||
typedef Fun type(typename a_<Args>::type::result_type...);
|
||||
};
|
||||
template<typename... Args>
|
||||
struct function_
|
||||
: public sprout::breed::detail::poly_function_traits<
|
||||
Fun,
|
||||
typename fun_<Args...>::type
|
||||
>
|
||||
{};
|
||||
public:
|
||||
template<long N>
|
||||
struct a {
|
||||
public:
|
||||
typedef typename a_<typename sprout::tppack_at<N, Args...>::type>::type type;
|
||||
};
|
||||
template<long N>
|
||||
struct b {
|
||||
public:
|
||||
typedef typename a_<typename sprout::tppack_at<N, Args...>::type>::type::result_type type;
|
||||
};
|
||||
typedef function_<Args...> function_traits;
|
||||
typedef typename function_traits::result_type result_type;
|
||||
SPROUT_CONSTEXPR result_type operator ()(
|
||||
typename impl2::expr_param e,
|
||||
typename impl2::state_param s,
|
||||
typename impl2::data_param d
|
||||
) const
|
||||
{
|
||||
return typename function_traits::function_type()(
|
||||
sprout::breed::detail::as_lvalue(typename a_<Args>::type()(e, s, d))...
|
||||
);
|
||||
}
|
||||
};
|
||||
};
|
||||
//
|
||||
// is_callable
|
||||
//
|
||||
template<typename Fun>
|
||||
struct is_callable<sprout::breed::call<Fun> >
|
||||
: public std::true_type
|
||||
{};
|
||||
} // namespace breed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_BREED_TRANSFORM_CALL_HPP
|
166
sprout/breed/transform/impl.hpp
Normal file
166
sprout/breed/transform/impl.hpp
Normal file
|
@ -0,0 +1,166 @@
|
|||
#ifndef SPROUT_BREED_TRANSFORM_IMPL_HPP
|
||||
#define SPROUT_BREED_TRANSFORM_IMPL_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/breed/breed_fwd.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace breed {
|
||||
//
|
||||
// SPROUT_BREED_TRANSFORM_
|
||||
//
|
||||
# define SPROUT_BREED_TRANSFORM_(PrimitiveTransform, X) \
|
||||
public: \
|
||||
SPROUT_BREED_CALLABLE() \
|
||||
typedef X breed_is_transform_; \
|
||||
typedef PrimitiveTransform transform_type; \
|
||||
public: \
|
||||
template<typename Sig> \
|
||||
struct result { \
|
||||
public: \
|
||||
typedef typename sprout::breed::detail::apply_transform<Sig>::result_type type; \
|
||||
}; \
|
||||
template<typename Expr> \
|
||||
SPROUT_CONSTEXPR typename sprout::breed::detail::apply_transform< \
|
||||
transform_type(Expr const&) \
|
||||
>::result_type operator()(Expr&& e) const { \
|
||||
return sprout::breed::detail::apply_transform< \
|
||||
transform_type(Expr const&) \
|
||||
>()(e, 0, 0); \
|
||||
} \
|
||||
template<typename Expr, typename State> \
|
||||
SPROUT_CONSTEXPR typename sprout::breed::detail::apply_transform< \
|
||||
transform_type(Expr const&, State const&) \
|
||||
>::result_type operator()(Expr&& e, State&& s) const \
|
||||
{ \
|
||||
return sprout::breed::detail::apply_transform< \
|
||||
transform_type(Expr const&, State const&) \
|
||||
>()(e, s, 0); \
|
||||
} \
|
||||
template<typename Expr, typename State, typename Data> \
|
||||
SPROUT_CONSTEXPR typename sprout::breed::detail::apply_transform< \
|
||||
transform_type(Expr const&, State const&, Data const&) \
|
||||
>::result_type operator()(Expr&& e, State&& s, Data&& d) const { \
|
||||
return sprout::breed::detail::apply_transform< \
|
||||
transform_type(Expr const&, State const&, Data const&) \
|
||||
>()(e, s, d); \
|
||||
}
|
||||
//
|
||||
// SPROUT_BREED_TRANSFORM
|
||||
//
|
||||
# define SPROUT_BREED_TRANSFORM(PrimitiveTransform) \
|
||||
SPROUT_BREED_TRANSFORM_(PrimitiveTransform, void)
|
||||
|
||||
namespace detail {
|
||||
template<typename Sig>
|
||||
struct apply_transform;
|
||||
template<typename PrimitiveTransform, typename Expr>
|
||||
struct apply_transform<PrimitiveTransform(Expr)>
|
||||
: public PrimitiveTransform::template impl<Expr, int, int>
|
||||
{};
|
||||
template<typename PrimitiveTransform, typename Expr, typename State>
|
||||
struct apply_transform<PrimitiveTransform(Expr, State)>
|
||||
: public PrimitiveTransform::template impl<Expr, State, int>
|
||||
{};
|
||||
template<typename PrimitiveTransform, typename Expr, typename State, typename Data>
|
||||
struct apply_transform<PrimitiveTransform(Expr, State, Data)>
|
||||
: public PrimitiveTransform::template impl<Expr, State, Data>
|
||||
{};
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// transform
|
||||
//
|
||||
template<typename PrimitiveTransform, typename X>
|
||||
struct transform {
|
||||
public:
|
||||
SPROUT_BREED_TRANSFORM_(PrimitiveTransform, X);
|
||||
};
|
||||
|
||||
//
|
||||
// transform_impl
|
||||
//
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct transform_impl {
|
||||
public:
|
||||
typedef Expr const expr;
|
||||
typedef Expr const& expr_param;
|
||||
typedef State const state;
|
||||
typedef State const& state_param;
|
||||
typedef Data const data;
|
||||
typedef Data const& data_param;
|
||||
};
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct transform_impl<Expr&, State, Data> {
|
||||
public:
|
||||
typedef Expr expr;
|
||||
typedef Expr& expr_param;
|
||||
typedef State const state;
|
||||
typedef State const& state_param;
|
||||
typedef Data const data;
|
||||
typedef Data const& data_param;
|
||||
};
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct transform_impl<Expr, State&, Data> {
|
||||
public:
|
||||
typedef Expr const expr;
|
||||
typedef Expr const& expr_param;
|
||||
typedef State state;
|
||||
typedef State& state_param;
|
||||
typedef Data const data;
|
||||
typedef Data const& data_param;
|
||||
};
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct transform_impl<Expr, State, Data&> {
|
||||
public:
|
||||
typedef Expr const expr;
|
||||
typedef Expr const& expr_param;
|
||||
typedef State const state;
|
||||
typedef State const& state_param;
|
||||
typedef Data data;
|
||||
typedef Data& data_param;
|
||||
};
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct transform_impl<Expr&, State&, Data> {
|
||||
public:
|
||||
typedef Expr expr;
|
||||
typedef Expr& expr_param;
|
||||
typedef State state;
|
||||
typedef State& state_param;
|
||||
typedef Data const data;
|
||||
typedef Data const& data_param;
|
||||
};
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct transform_impl<Expr&, State, Data&> {
|
||||
public:
|
||||
typedef Expr expr;
|
||||
typedef Expr& expr_param;
|
||||
typedef State const state;
|
||||
typedef State const& state_param;
|
||||
typedef Data data;
|
||||
typedef Data& data_param;
|
||||
};
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct transform_impl<Expr, State&, Data&> {
|
||||
public:
|
||||
typedef Expr const expr;
|
||||
typedef Expr const& expr_param;
|
||||
typedef State state;
|
||||
typedef State& state_param;
|
||||
typedef Data data;
|
||||
typedef Data& data_param;
|
||||
};
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct transform_impl<Expr&, State&, Data&> {
|
||||
public:
|
||||
typedef Expr expr;
|
||||
typedef Expr& expr_param;
|
||||
typedef State state;
|
||||
typedef State& state_param;
|
||||
typedef Data data;
|
||||
typedef Data& data_param;
|
||||
};
|
||||
} // namespace breed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_BREED_TRANSFORM_IMPL_HPP
|
129
sprout/breed/transform/pass_through.hpp
Normal file
129
sprout/breed/transform/pass_through.hpp
Normal file
|
@ -0,0 +1,129 @@
|
|||
#ifndef SPROUT_BREED_TRANSFORM_PASS_THROUGH_HPP
|
||||
#define SPROUT_BREED_TRANSFORM_PASS_THROUGH_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/index_tuple.hpp>
|
||||
#include <sprout/breed/breed_fwd.hpp>
|
||||
#include <sprout/breed/args.hpp>
|
||||
#include <sprout/breed/transform/impl.hpp>
|
||||
#include <sprout/breed/detail/std_result_of.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace breed {
|
||||
namespace detail {
|
||||
template<
|
||||
typename Grammar,
|
||||
typename Expr,
|
||||
typename State,
|
||||
typename Data,
|
||||
long Arity = sprout::breed::arity_of<Expr>::value
|
||||
>
|
||||
struct pass_through_impl
|
||||
: public sprout::breed::transform_impl<Expr, State, Data>
|
||||
{
|
||||
public:
|
||||
typedef typename pass_through_impl::expr unref_expr;
|
||||
private:
|
||||
template<typename IndexTuple>
|
||||
struct list_impl {};
|
||||
template<std::ptrdiff_t... Indexes>
|
||||
struct list_impl<sprout::index_tuple<Indexes...> > {
|
||||
public:
|
||||
typedef sprout::breed::list<
|
||||
typename Grammar::template breed_child<Indexes>::type::template impl<
|
||||
typename sprout::breed::result_of::child_c<Expr, Indexes>::type,
|
||||
State,
|
||||
Data
|
||||
>::result_type...
|
||||
> type;
|
||||
};
|
||||
public:
|
||||
typedef typename sprout::breed::base_expr<
|
||||
typename unref_expr::breed_domain,
|
||||
typename unref_expr::breed_tag,
|
||||
typename list_impl<typename sprout::index_range<0, Arity>::type>::type
|
||||
>::type expr_type;
|
||||
typedef typename unref_expr::breed_generator breed_generator;
|
||||
typedef typename sprout::breed::detail::std_result_of<
|
||||
breed_generator(expr_type)
|
||||
>::type result_type;
|
||||
private:
|
||||
template<std::ptrdiff_t... Indexes>
|
||||
SPROUT_CONSTEXPR result_type call_impl(
|
||||
typename pass_through_impl::expr_param e,
|
||||
typename pass_through_impl::state_param s,
|
||||
typename pass_through_impl::data_param d,
|
||||
sprout::index_tuple<Indexes...>
|
||||
) const
|
||||
{
|
||||
return breed_generator()(
|
||||
expr_type(
|
||||
typename Grammar::template breed_child<Indexes>::type::template impl<
|
||||
typename sprout::breed::result_of::child_c<Expr, Indexes>::type,
|
||||
State,
|
||||
Data
|
||||
>()(e.proto_base().template child<Indexes>(), s, d)...
|
||||
)
|
||||
);
|
||||
}
|
||||
public:
|
||||
SPROUT_CONSTEXPR result_type operator()(
|
||||
typename pass_through_impl::expr_param e,
|
||||
typename pass_through_impl::state_param s,
|
||||
typename pass_through_impl::data_param d
|
||||
) const
|
||||
{
|
||||
return call_impl(e, s, d, typename sprout::index_range<0, Arity>::type());
|
||||
}
|
||||
};
|
||||
template<typename Grammar, typename Expr, typename State, typename Data>
|
||||
struct pass_through_impl<Grammar, Expr, State, Data, 0>
|
||||
: public sprout::breed::transform_impl<Expr, State, Data>
|
||||
{
|
||||
public:
|
||||
typedef Expr result_type;
|
||||
public:
|
||||
#ifdef SPROUT_BREED_STRICT_RESULT_OF
|
||||
SPROUT_CONSTEXPR result_type
|
||||
#else
|
||||
SPROUT_CONSTEXPR typename pass_through_impl::expr_param
|
||||
#endif
|
||||
operator()(
|
||||
typename pass_through_impl::expr_param e,
|
||||
typename pass_through_impl::state_param,
|
||||
typename pass_through_impl::data_param
|
||||
) const
|
||||
{
|
||||
return e;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// pass_through
|
||||
//
|
||||
template<typename Grammar>
|
||||
struct pass_through
|
||||
: public sprout::breed::transform<sprout::breed::pass_through<Grammar> >
|
||||
{
|
||||
public:
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl
|
||||
: public sprout::breed::detail::pass_through_impl<Grammar, Expr, State, Data>
|
||||
{};
|
||||
};
|
||||
|
||||
//
|
||||
// is_callable
|
||||
//
|
||||
template<typename Grammar>
|
||||
struct is_callable<sprout::breed::pass_through<Grammar> >
|
||||
: public std::true_type
|
||||
{};
|
||||
} // namespace breed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_BREED_TRANSFORM_PASS_THROUGH_HPP
|
126
sprout/breed/transform/when.hpp
Normal file
126
sprout/breed/transform/when.hpp
Normal file
|
@ -0,0 +1,126 @@
|
|||
#ifndef SPROUT_BREED_TRANSFORM_WHEN_HPP
|
||||
#define SPROUT_BREED_TRANSFORM_WHEN_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type/type_tuple.hpp>
|
||||
#include <sprout/type/iterator/deref.hpp>
|
||||
#include <sprout/type/seq/algorithm/find_if.hpp>
|
||||
#include <sprout/breed/breed_fwd.hpp>
|
||||
#include <sprout/breed/traits.hpp>
|
||||
#include <sprout/breed/transform/call.hpp>
|
||||
#include <sprout/breed/transform/make.hpp>
|
||||
#include <sprout/breed/transform/impl.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace breed {
|
||||
//
|
||||
// when
|
||||
//
|
||||
template<typename Grammar, typename PrimitiveTransform>
|
||||
struct when
|
||||
: public PrimitiveTransform
|
||||
{
|
||||
public:
|
||||
typedef Grammar first;
|
||||
typedef PrimitiveTransform second;
|
||||
typedef typename Grammar::breed_grammar breed_grammar;
|
||||
};
|
||||
template<typename Grammar, typename Fun>
|
||||
struct when<Grammar, Fun*>
|
||||
: public sprout::breed::when<Grammar, Fun>
|
||||
{};
|
||||
template<typename Grammar>
|
||||
struct when<Grammar, sprout::breed::external_transform>
|
||||
: public sprout::breed::transform<when<Grammar, sprout::breed::external_transform> >
|
||||
{
|
||||
public:
|
||||
typedef Grammar first;
|
||||
typedef external_transform second;
|
||||
typedef typename Grammar::breed_grammar breed_grammar;
|
||||
public:
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl
|
||||
: public Data::template when<Grammar>::template impl<Expr, State, Data>
|
||||
{};
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl<Expr, State, Data&>
|
||||
: public Data::template when<Grammar>::template impl<Expr, State, Data&>
|
||||
{};
|
||||
};
|
||||
template<typename Grammar, typename R, typename... Args>
|
||||
struct when<Grammar, R(Args...)>
|
||||
: public sprout::breed::transform<when<Grammar, R(Args...)> >
|
||||
{
|
||||
public:
|
||||
typedef Grammar first;
|
||||
typedef R second(Args...);
|
||||
typedef typename Grammar::breed_grammar breed_grammar;
|
||||
public:
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl
|
||||
: public sprout::breed::transform_impl<Expr, State, Data>
|
||||
{
|
||||
public:
|
||||
typedef typename std::conditional<
|
||||
sprout::breed::is_callable<R>::value,
|
||||
sprout::breed::call<R(Args...)>,
|
||||
sprout::breed::make<R(Args...)>
|
||||
>::type which;
|
||||
typedef typename which::template impl<Expr, State, Data>::result_type result_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR result_type operator()(
|
||||
typename impl::expr_param e,
|
||||
typename impl::state_param s,
|
||||
typename impl::data_param d
|
||||
) const
|
||||
{
|
||||
return typename which::template impl<Expr, State, Data>()(e, s, d);
|
||||
}
|
||||
};
|
||||
};
|
||||
//
|
||||
// is_callable
|
||||
//
|
||||
template<typename Grammar, typename Transform>
|
||||
struct is_callable<sprout::breed::when<Grammar, Transform> >
|
||||
: public std::true_type
|
||||
{};
|
||||
//
|
||||
// otherwise
|
||||
//
|
||||
template<typename Fun>
|
||||
struct otherwise
|
||||
: public sprout::breed::when<sprout::breed::_, Fun>
|
||||
{};
|
||||
//
|
||||
// external_transforms
|
||||
//
|
||||
template<typename... Args>
|
||||
struct external_transforms {
|
||||
public:
|
||||
typedef sprout::types::type_tuple<Args...> map_type;
|
||||
private:
|
||||
template<typename Rule>
|
||||
struct map_pred {
|
||||
public:
|
||||
template<typename T>
|
||||
struct apply
|
||||
: public std::is_same<Rule, typename T::first>
|
||||
{};
|
||||
};
|
||||
public:
|
||||
template<typename Rule>
|
||||
struct when
|
||||
: public sprout::breed::when<
|
||||
sprout::breed::_,
|
||||
sprout::types::deref<
|
||||
typename sprout::types::find_if<map_type, map_pred<Rule> >::type
|
||||
>::type
|
||||
>
|
||||
{};
|
||||
};
|
||||
} // namespace breed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_BREED_TRANSFORM_WHEN_HPP
|
Loading…
Add table
Add a link
Reference in a new issue