Re: Static polymorphism
You need to read about "template template parameters". Notice
'template' before CheckPolicyT below:
template <typename ActionsT = parse_actions,
template <typename, typename> class CheckPolicyT =
check_policy,
typename ErrorHandlerT = parse_error_handler>
struct grammar :
/* ... */
A compilable sample is below...
On Mar 21, 11:41 am, Olaf <o...@mdcc.de> wrote:
Hello,
for my data parser I want to use different generic checking policies
using static polymorphism. But the way I've used won't compile (concrete
the grammar class). The check policy passes the data the parse actions
which fills (and knows about) the data container.
What is the correct syntax for this? Note, that boost::spirit::grammar
self uses static polymorphism.
Thanks,
Olaf
---8<---
struct parse_actions { ... };
struct parse_error_handler { ... };
template<typename DerivedT, typename ActionsT>
struct check_policy
{
explicit check_policy( const ActionsT& actions )
...
};
template <typename ActionsT = parse_actions,
typename CheckPolicyT = check_policy,
typename ErrorHandlerT = parse_error_handler>
struct grammar :
CheckPolicyT< grammar<CheckPolicyT, ActionsT, ErrorHandlerT> >,
boost::spirit::grammar<
grammar<CheckPolicyT, ActionsT, ErrorHandlerT>
>
{
explicit grammar(const ActionsT& actions = ActionsT(),
const ErrorHandlerT& handler = ErrorHandlerT())
: CheckPolicyT( actions ),
actions(actions),
error_handler(handler)
{ }
--->8---
struct parse_actions { };
struct parse_error_handler { };
template<typename DerivedT, typename ActionsT>
struct check_policy
{
explicit check_policy( const ActionsT& actions )
{}
};
template <typename ActionsT = parse_actions,
template <typename, typename> class CheckPolicyT =
check_policy,
typename ErrorHandlerT = parse_error_handler>
struct grammar :
CheckPolicyT< grammar<parse_actions, CheckPolicyT, ErrorHandlerT>,
ActionsT >,
boost::spirit::grammar<
grammar<ActionsT, CheckPolicyT, ErrorHandlerT>
>
{
explicit grammar(const ActionsT& actions = ActionsT(),
const ErrorHandlerT& handler = ErrorHandlerT())
: CheckPolicyT<grammar<ActionsT, CheckPolicyT, ErrorHandlerT>,
ActionsT>( actions )
{ }
};
Ali