123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947 |
- #ifndef BOOST_PROTO_MATCHES_HPP_EAN_11_03_2006
- #define BOOST_PROTO_MATCHES_HPP_EAN_11_03_2006
- #include <boost/config.hpp>
- #include <boost/detail/workaround.hpp>
- #include <boost/preprocessor/cat.hpp>
- #include <boost/preprocessor/arithmetic/dec.hpp>
- #include <boost/preprocessor/arithmetic/sub.hpp>
- #include <boost/preprocessor/iteration/iterate.hpp>
- #include <boost/preprocessor/facilities/intercept.hpp>
- #include <boost/preprocessor/punctuation/comma_if.hpp>
- #include <boost/preprocessor/repetition/enum.hpp>
- #include <boost/preprocessor/repetition/enum_params.hpp>
- #include <boost/preprocessor/repetition/enum_shifted.hpp>
- #include <boost/preprocessor/repetition/enum_binary_params.hpp>
- #include <boost/preprocessor/repetition/enum_shifted_params.hpp>
- #include <boost/preprocessor/repetition/enum_trailing_params.hpp>
- #include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
- #include <boost/preprocessor/repetition/repeat.hpp>
- #include <boost/config.hpp>
- #include <boost/mpl/logical.hpp>
- #include <boost/mpl/eval_if.hpp>
- #include <boost/proto/detail/template_arity.hpp>
- #include <boost/utility/enable_if.hpp>
- #if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
- #include <boost/type_traits/is_array.hpp>
- #endif
- #include <boost/type_traits/is_const.hpp>
- #include <boost/type_traits/is_convertible.hpp>
- #include <boost/type_traits/is_reference.hpp>
- #include <boost/type_traits/is_pointer.hpp>
- #include <boost/proto/proto_fwd.hpp>
- #include <boost/proto/traits.hpp>
- #include <boost/proto/transform/when.hpp>
- #include <boost/proto/transform/impl.hpp>
- #if defined(_MSC_VER)
- # pragma warning(push)
- # pragma warning(disable:4305)
- #endif
- #define BOOST_PROTO_LOGICAL_typename_G BOOST_PP_ENUM_PARAMS(BOOST_PROTO_MAX_LOGICAL_ARITY, typename G)
- #define BOOST_PROTO_LOGICAL_G BOOST_PP_ENUM_PARAMS(BOOST_PROTO_MAX_LOGICAL_ARITY, G)
- namespace boost { namespace proto
- {
- namespace detail
- {
- template<typename Expr, typename BasicExpr, typename Grammar>
- struct matches_;
- template<bool B, typename Pred>
- struct and_2;
- template<typename And, typename Expr, typename State, typename Data>
- struct _and_impl;
- template<typename T, typename U>
- struct array_matches
- : mpl::false_
- {};
- template<typename T, std::size_t M>
- struct array_matches<T[M], T *>
- : mpl::true_
- {};
- template<typename T, std::size_t M>
- struct array_matches<T[M], T const *>
- : mpl::true_
- {};
- template<typename T, std::size_t M>
- struct array_matches<T[M], T[proto::N]>
- : mpl::true_
- {};
- template<typename T, typename U
- BOOST_PROTO_TEMPLATE_ARITY_PARAM(long Arity = detail::template_arity<U>::value)
- >
- struct lambda_matches
- : mpl::false_
- {};
- template<typename T>
- struct lambda_matches<T, proto::_ BOOST_PROTO_TEMPLATE_ARITY_PARAM(-1)>
- : mpl::true_
- {};
- template<typename T>
- struct lambda_matches<T, T BOOST_PROTO_TEMPLATE_ARITY_PARAM(-1)>
- : mpl::true_
- {};
- template<typename T, std::size_t M, typename U>
- struct lambda_matches<T[M], U BOOST_PROTO_TEMPLATE_ARITY_PARAM(-1)>
- : array_matches<T[M], U>
- {};
- template<typename T, std::size_t M>
- struct lambda_matches<T[M], _ BOOST_PROTO_TEMPLATE_ARITY_PARAM(-1)>
- : mpl::true_
- {};
- template<typename T, std::size_t M>
- struct lambda_matches<T[M], T[M] BOOST_PROTO_TEMPLATE_ARITY_PARAM(-1)>
- : mpl::true_
- {};
- template<template<typename> class T, typename Expr0, typename Grammar0>
- struct lambda_matches<T<Expr0>, T<Grammar0> BOOST_PROTO_TEMPLATE_ARITY_PARAM(1) >
- : lambda_matches<Expr0, Grammar0>
- {};
-
- template<typename Args1, typename Back, long From, long To>
- struct vararg_matches_impl;
-
- template<typename Expr, typename Args1, typename Args2, typename Back, bool Can, bool Zero, typename Void = void>
- struct vararg_matches
- : mpl::false_
- {};
- template<typename Expr, typename Args1, typename Args2, typename Back>
- struct vararg_matches<Expr, Args1, Args2, Back, true, true, typename Back::proto_is_vararg_>
- : matches_<
- Expr
- , proto::basic_expr<ignore, Args1, Args1::arity>
- , proto::basic_expr<ignore, Args2, Args1::arity>
- >
- {};
- template<typename Expr, typename Args1, typename Args2, typename Back>
- struct vararg_matches<Expr, Args1, Args2, Back, true, false, typename Back::proto_is_vararg_>
- : and_2<
- matches_<
- Expr
- , proto::basic_expr<ignore, Args1, Args2::arity>
- , proto::basic_expr<ignore, Args2, Args2::arity>
- >::value
- , vararg_matches_impl<Args1, typename Back::proto_grammar, Args2::arity + 1, Args1::arity>
- >
- {};
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template<typename T, typename U>
- struct is_cv_ref_compatible
- : mpl::true_
- {};
- template<typename T, typename U>
- struct is_cv_ref_compatible<T, U &>
- : mpl::false_
- {};
- template<typename T, typename U>
- struct is_cv_ref_compatible<T &, U &>
- : mpl::bool_<is_const<T>::value == is_const<U>::value>
- {};
- #if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
-
-
-
- template<
- typename T
- , typename U
- , bool B = is_array<BOOST_PROTO_UNCVREF(T)>::value
- >
- struct terminal_array_matches
- : mpl::false_
- {};
- template<typename T, typename U, std::size_t M>
- struct terminal_array_matches<T, U(&)[M], true>
- : is_convertible<T, U(&)[M]>
- {};
- template<typename T, typename U>
- struct terminal_array_matches<T, U(&)[proto::N], true>
- : is_convertible<T, U *>
- {};
- template<typename T, typename U>
- struct terminal_array_matches<T, U *, true>
- : is_convertible<T, U *>
- {};
-
- template<typename T, typename U>
- struct terminal_matches
- : mpl::or_<
- mpl::and_<
- is_cv_ref_compatible<T, U>
- , lambda_matches<
- BOOST_PROTO_UNCVREF(T)
- , BOOST_PROTO_UNCVREF(U)
- >
- >
- , terminal_array_matches<T, U>
- >
- {};
- #else
-
- template<typename T, typename U>
- struct terminal_matches
- : mpl::and_<
- is_cv_ref_compatible<T, U>
- , lambda_matches<
- BOOST_PROTO_UNCVREF(T)
- , BOOST_PROTO_UNCVREF(U)
- >
- >
- {};
- template<typename T, std::size_t M>
- struct terminal_matches<T(&)[M], T(&)[proto::N]>
- : mpl::true_
- {};
- template<typename T, std::size_t M>
- struct terminal_matches<T(&)[M], T *>
- : mpl::true_
- {};
-
- #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
- template<typename T, std::size_t M>
- struct terminal_matches<T const (&)[M], T const[M]>
- : mpl::true_
- {};
- #endif
- #endif
- template<typename T>
- struct terminal_matches<T, T>
- : mpl::true_
- {};
- template<typename T>
- struct terminal_matches<T &, T>
- : mpl::true_
- {};
- template<typename T>
- struct terminal_matches<T const &, T>
- : mpl::true_
- {};
- template<typename T>
- struct terminal_matches<T, proto::_>
- : mpl::true_
- {};
- template<typename T>
- struct terminal_matches<T, exact<T> >
- : mpl::true_
- {};
- template<typename T, typename U>
- struct terminal_matches<T, proto::convertible_to<U> >
- : is_convertible<T, U>
- {};
-
- template<typename Expr, typename BasicExpr, typename Grammar>
- struct matches_
- : mpl::false_
- {};
- template<typename Expr, typename BasicExpr>
- struct matches_< Expr, BasicExpr, proto::_ >
- : mpl::true_
- {};
- template<typename Expr, typename Tag, typename Args1, long N1, typename Args2, long N2>
- struct matches_< Expr, proto::basic_expr<Tag, Args1, N1>, proto::basic_expr<Tag, Args2, N2> >
- : vararg_matches< Expr, Args1, Args2, typename Args2::back_, (N1+2 > N2), (N2 > N1) >
- {};
- template<typename Expr, typename Tag, typename Args1, long N1, typename Args2, long N2>
- struct matches_< Expr, proto::basic_expr<Tag, Args1, N1>, proto::basic_expr<proto::_, Args2, N2> >
- : vararg_matches< Expr, Args1, Args2, typename Args2::back_, (N1+2 > N2), (N2 > N1) >
- {};
- template<typename Expr, typename Tag, typename Args1, typename Args2>
- struct matches_< Expr, proto::basic_expr<Tag, Args1, 0>, proto::basic_expr<Tag, Args2, 0> >
- : terminal_matches<typename Args1::child0, typename Args2::child0>
- {};
- template<typename Expr, typename Tag, typename Args1, typename Args2, long N2>
- struct matches_< Expr, proto::basic_expr<Tag, Args1, 0>, proto::basic_expr<proto::_, Args2, N2> >
- : mpl::false_
- {};
- template<typename Expr, typename Tag, typename Args1, typename Args2>
- struct matches_< Expr, proto::basic_expr<Tag, Args1, 0>, proto::basic_expr<proto::_, Args2, 0> >
- : terminal_matches<typename Args1::child0, typename Args2::child0>
- {};
- template<typename Expr, typename Tag, typename Args1, typename Args2>
- struct matches_< Expr, proto::basic_expr<Tag, Args1, 1>, proto::basic_expr<Tag, Args2, 1> >
- : matches_<
- typename detail::expr_traits<typename Args1::child0>::value_type::proto_derived_expr
- , typename detail::expr_traits<typename Args1::child0>::value_type::proto_grammar
- , typename Args2::child0::proto_grammar
- >
- {};
- template<typename Expr, typename Tag, typename Args1, typename Args2>
- struct matches_< Expr, proto::basic_expr<Tag, Args1, 1>, proto::basic_expr<proto::_, Args2, 1> >
- : matches_<
- typename detail::expr_traits<typename Args1::child0>::value_type::proto_derived_expr
- , typename detail::expr_traits<typename Args1::child0>::value_type::proto_grammar
- , typename Args2::child0::proto_grammar
- >
- {};
- #include <boost/proto/detail/and_n.hpp>
- #include <boost/proto/detail/or_n.hpp>
- #include <boost/proto/detail/matches_.hpp>
- #include <boost/proto/detail/vararg_matches_impl.hpp>
- #include <boost/proto/detail/lambda_matches.hpp>
-
- template<typename Expr, typename Tag, typename Args, long Arity, typename If, typename Then, typename Else>
- struct matches_<Expr, proto::basic_expr<Tag, Args, Arity>, proto::if_<If, Then, Else> >
- : mpl::eval_if_c<
- static_cast<bool>(
- remove_reference<
- typename when<_, If>::template impl<Expr, int, int>::result_type
- >::type::value
- )
- , matches_<Expr, proto::basic_expr<Tag, Args, Arity>, typename Then::proto_grammar>
- , matches_<Expr, proto::basic_expr<Tag, Args, Arity>, typename Else::proto_grammar>
- >::type
- {
- typedef
- typename mpl::if_c<
- static_cast<bool>(
- remove_reference<
- typename when<_, If>::template impl<Expr, int, int>::result_type
- >::type::value
- )
- , Then
- , Else
- >::type
- which;
- };
-
- template<typename Expr, typename BasicExpr>
- struct matches_<Expr, BasicExpr, or_<> >
- : mpl::false_
- {
- typedef not_<_> which;
- };
- template<typename Expr, typename BasicExpr, typename G0>
- struct matches_<Expr, BasicExpr, or_<G0> >
- : matches_<Expr, BasicExpr, typename G0::proto_grammar>
- {
- typedef G0 which;
- };
-
- template<typename Expr, typename BasicExpr>
- struct matches_<Expr, BasicExpr, and_<> >
- : mpl::true_
- {};
- template<typename Expr, typename BasicExpr, typename G0>
- struct matches_<Expr, BasicExpr, and_<G0> >
- : matches_<Expr, BasicExpr, typename G0::proto_grammar>
- {};
-
- template<typename Expr, typename BasicExpr, typename Grammar>
- struct matches_<Expr, BasicExpr, not_<Grammar> >
- : mpl::not_<matches_<Expr, BasicExpr, typename Grammar::proto_grammar> >
- {};
-
- template<typename Expr, typename Tag, typename Args, long Arity, typename Cases, typename Transform>
- struct matches_<Expr, proto::basic_expr<Tag, Args, Arity>, switch_<Cases, Transform> >
- : matches_<
- Expr
- , proto::basic_expr<Tag, Args, Arity>
- , typename Cases::template case_<
- typename when<_,Transform>::template impl<Expr,int,int>::result_type
- >::proto_grammar
- >
- {
- typedef
- typename Cases::template case_<
- typename when<_, Transform>::template impl<Expr, int, int>::result_type
- >
- which;
- };
-
- template<typename Expr, typename Tag, typename Args, long Arity, typename Cases>
- struct matches_<Expr, proto::basic_expr<Tag, Args, Arity>, switch_<Cases> >
- : matches_<
- Expr
- , proto::basic_expr<Tag, Args, Arity>
- , typename Cases::template case_<Tag>::proto_grammar
- >
- {
- typedef typename Cases::template case_<Tag> which;
- };
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template<typename Expr, typename Grammar>
- struct matches
- : detail::matches_<
- typename Expr::proto_derived_expr
- , typename Expr::proto_grammar
- , typename Grammar::proto_grammar
- >
- {};
-
-
- template<typename Expr, typename Grammar>
- struct matches<Expr &, Grammar>
- : detail::matches_<
- typename Expr::proto_derived_expr
- , typename Expr::proto_grammar
- , typename Grammar::proto_grammar
- >
- {};
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- struct _ : transform<_>
- {
- typedef _ proto_grammar;
- template<typename Expr, typename State, typename Data>
- struct impl : transform_impl<Expr, State, Data>
- {
- typedef Expr result_type;
-
-
- BOOST_PROTO_RETURN_TYPE_STRICT_LOOSE(result_type, typename impl::expr_param)
- operator()(
- typename impl::expr_param e
- , typename impl::state_param
- , typename impl::data_param
- ) const
- {
- return e;
- }
- };
- };
- namespace detail
- {
- template<typename Expr, typename State, typename Data>
- struct _and_impl<proto::and_<>, Expr, State, Data>
- : proto::_::impl<Expr, State, Data>
- {};
- template<typename G0, typename Expr, typename State, typename Data>
- struct _and_impl<proto::and_<G0>, Expr, State, Data>
- : proto::when<proto::_, G0>::template impl<Expr, State, Data>
- {};
- }
-
-
-
-
-
-
-
- template<typename Grammar>
- struct not_ : transform<not_<Grammar> >
- {
- typedef not_ proto_grammar;
- template<typename Expr, typename State, typename Data>
- struct impl : transform_impl<Expr, State, Data>
- {
- typedef Expr result_type;
-
-
-
- BOOST_PROTO_RETURN_TYPE_STRICT_LOOSE(result_type, typename impl::expr_param)
- operator()(
- typename impl::expr_param e
- , typename impl::state_param
- , typename impl::data_param
- ) const
- {
- return e;
- }
- };
- };
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template<
- typename If
- , typename Then
- , typename Else
- >
- struct if_ : transform<if_<If, Then, Else> >
- {
- typedef if_ proto_grammar;
- template<typename Expr, typename State, typename Data>
- struct impl : transform_impl<Expr, State, Data>
- {
- typedef
- typename when<_, If>::template impl<Expr, State, Data>::result_type
- condition;
- typedef
- typename mpl::if_c<
- static_cast<bool>(remove_reference<condition>::type::value)
- , when<_, Then>
- , when<_, Else>
- >::type
- which;
- typedef typename which::template impl<Expr, State, Data>::result_type result_type;
-
-
-
-
- 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);
- }
- };
- };
-
-
-
-
-
-
-
-
-
-
-
-
- template<BOOST_PROTO_LOGICAL_typename_G>
- struct or_ : transform<or_<BOOST_PROTO_LOGICAL_G> >
- {
- typedef or_ proto_grammar;
-
-
-
-
-
-
- template<typename Expr, typename State, typename Data>
- struct impl
- : detail::matches_<
- typename Expr::proto_derived_expr
- , typename Expr::proto_grammar
- , or_
- >::which::template impl<Expr, State, Data>
- {};
- template<typename Expr, typename State, typename Data>
- struct impl<Expr &, State, Data>
- : detail::matches_<
- typename Expr::proto_derived_expr
- , typename Expr::proto_grammar
- , or_
- >::which::template impl<Expr &, State, Data>
- {};
- };
-
-
-
-
-
-
-
-
-
-
- template<BOOST_PROTO_LOGICAL_typename_G>
- struct and_ : transform<and_<BOOST_PROTO_LOGICAL_G> >
- {
- typedef and_ proto_grammar;
- template<typename Expr, typename State, typename Data>
- struct impl
- : detail::_and_impl<and_, Expr, State, Data>
- {};
- };
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template<typename Cases, typename Transform>
- struct switch_ : transform<switch_<Cases, Transform> >
- {
- typedef switch_ proto_grammar;
- template<typename Expr, typename State, typename Data>
- struct impl
- : Cases::template case_<
- typename when<_, Transform>::template impl<Expr, State, Data>::result_type
- >::template impl<Expr, State, Data>
- {};
- };
-
-
- template<typename Cases>
- struct switch_<Cases> : transform<switch_<Cases> >
- {
- typedef switch_ proto_grammar;
- template<typename Expr, typename State, typename Data>
- struct impl
- : Cases::template case_<typename Expr::proto_tag>::template impl<Expr, State, Data>
- {};
- template<typename Expr, typename State, typename Data>
- struct impl<Expr &, State, Data>
- : Cases::template case_<typename Expr::proto_tag>::template impl<Expr &, State, Data>
- {};
- };
-
-
-
-
-
-
-
-
-
-
- template<typename T>
- struct exact
- {};
-
-
-
-
-
-
-
-
-
-
- template<typename T>
- struct convertible_to
- {};
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template<typename Grammar>
- struct vararg
- : Grammar
- {
-
- typedef void proto_is_vararg_;
- };
-
-
- template<BOOST_PROTO_LOGICAL_typename_G>
- struct is_callable<or_<BOOST_PROTO_LOGICAL_G> >
- : mpl::true_
- {};
-
-
- template<BOOST_PROTO_LOGICAL_typename_G>
- struct is_callable<and_<BOOST_PROTO_LOGICAL_G> >
- : mpl::true_
- {};
-
-
- template<typename Grammar>
- struct is_callable<not_<Grammar> >
- : mpl::true_
- {};
-
-
- template<typename If, typename Then, typename Else>
- struct is_callable<if_<If, Then, Else> >
- : mpl::true_
- {};
-
-
- template<typename Grammar>
- struct is_callable<vararg<Grammar> >
- : mpl::true_
- {};
-
-
- template<typename Cases, typename Transform>
- struct is_callable<switch_<Cases, Transform> >
- : mpl::true_
- {};
- }}
- #undef BOOST_PROTO_LOGICAL_typename_G
- #undef BOOST_PROTO_LOGICAL_G
- #if defined(_MSC_VER)
- # pragma warning(pop)
- #endif
- #endif
|