On Fri, 21 Nov 2014 13:39:42 +0000 monarch_dodra via Digitalmars-d <[email protected]> wrote:
> D has phenomenal meta programming possibilities, and I see more
> and more templates taking more and more parameters. So I thought
> to myself, why not have a template builder pattern?
i did something similar in my iv.writer (ctfe format string parser).
once i got about ten argumnets to each template (and growing), i moved
everything to structure.
struct WrData {
... fields ...
auto set(string name, T) (in T value)
if (__traits(hasMember, this, name))
{
__traits(getMember, this, name) = value;
return this;
}
}
and then i can pass the struct around, changing only the fields i want,
in "pseudo-functional" style:
template MyTpl!(WrData data) {
...
MyTpl!(data.set!"field0"(value0).set!"field1"(value1));
}
that was a real saver. but now i have to wait for GDC update, 'cause
2.065 frontend is not able to use structs as template args.
signature.asc
Description: PGP signature
