Storing a rule as a type

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Storing a rule as a type

Kent Hauser
Is there a generally accepted best practice when one needs a `type`, but has a rule. I have been using boost::mpl to configuration an application, and types are of course much easier to metaprogram.

In my application, it would be nice if I could encorporate a rule such as 

auto const qs = rule<class qs, std::string>(“quoted string”) = lexeme['"' >> *(char_ - '"') >> '"’];

into a type such as `qs_`.  I guess I could use `decltype` of a lambda in a pinch, but I was hoping for a more general best practice.

Thanks!
Kent



Sent from Mailbox

------------------------------------------------------------------------------

_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: Storing a rule as a type

Mario Lang
"Kent Hauser" <[hidden email]> writes:

> Is there a generally accepted best practice when one needs a `type`,
> but has a
> rule. I have been using boost::mpl to configuration an application,
> and types are of course much easier to metaprogram.
>
> In my application, it would be nice if I could encorporate a rule such as 
>
> auto const qs = rule<class qs, std::string>(“quoted string”) = lexeme['"' >> *(char_ - '"') >> '"’];
>
> into a type such as `qs_`.  I guess I could use `decltype` of a lambda in a pinch, but I was hoping for a more general best practice.

typedef or decltype, depending on what you're trying to achieve exactly.
Note, however, that the string "quoted string" and the actual rule
assignment is not part of the type.  If you reuse the type of that rule
somewhere else, you will have to reprovide a rule name, in case you want
to have a named rule.  Same for the actual rule content.

However, I am not sure if I understand what you are looking for
exactly.  Can you provide a more concrete example?

--
CYa,
  ⡍⠁⠗⠊⠕ | Debian Developer <URL:http://debian.org/>
  .''`. | Get my public key via finger mlang/[hidden email]
 : :' : | 1024D/7FC1A0854909BCCDBE6C102DDFFC022A6B113E44
 `. `'
   `-      <URL:http://delysid.org/>  <URL:http://www.staff.tugraz.at/mlang/>

------------------------------------------------------------------------------
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general