I just have to say that string mixins rock
Jonathan M Davis
jmdavisProg at gmx.com
Fri Jul 27 00:25:12 PDT 2012
On Thursday, July 26, 2012 08:48:33 Philippe Sigaud wrote:
> On Thu, Jul 26, 2012 at 8:24 AM, Jonathan M Davis <jmdavisProg at gmx.com>
wrote:
> > They've made my life way easier on a number of projects lately -
> > particularly involving parsing.
>
> Yeah D!
> Nice use of mixins. I was a bit meh at the beginning (2009?) but the
> combination of templates, CTFE which can be used to generate the
> string and/or tansform it and mixins to inject them on code is simply
> wonderful.
To make things even cooler, I just figured out that if I added with statements
into the mix, I don't even have to change the templates to know about which
fields are on which structs or to use a different template per struct or pass
the struct name to the template or anything like that. It just automatically
uses the field in the struct thanks to with.
> > On top of that, all I have to do is alter the few templates that I use to
> > generate the strings, and I can make it print out the value, or append it
> > to another buffer, or assign it to a corresponding field in a struct, so
> > on and so forth. It saves quite a bit of code duplication, and makes it
> > _really_ easy told change what a whole ton of lines of code do.
>
> You might want to use debug/log flags like this:
>
> mixin(parseUEV!("bit_depth_luma_minus8", Debug.yes));
>
> and then activate debugging/logging with static ifs inside the template.
Not a bad idea, though in most cases at this point, I either want everything
or nothing as far as debug output goes, so it wouldn't help much. In other
situations, I can see how it would be very useful though.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list