Extensible struct type via variadic template arguments
Joseph Rushton Wakeling via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Apr 11 15:23:54 PDT 2016
On Monday, 11 April 2016 at 22:06:00 UTC, ag0aep6g wrote:
>
> mixin template multipleEdgeProperties (EdgePropertyList...)
> {
> static if (EdgePropertyList.length >= 1)
> {
> mixin singleEdgeProperty!(EdgePropertyList[0]);
> mixin multipleEdgeProperties!(EdgePropertyList[1 .. $]);
> }
> }
>
> mixin template singleEdgeProperty (alias property)
> {
> mixin(`public property.Type[] ` ~ property.name ~ `;`);
> }
Ah, nice! I knew I was missing a trick somewhere with mixin
templates, but I haven't used them for sufficiently long that my
brain wasn't in the right place to find it. Your solution is
_much_ more elegant than what I have now.
> The string mixin is hidden away in singleEdgeProperty, but it's
> still there.
>
> To get rid of it, you'd have take a different approach, I think.
Yea, makes sense. I'm probably going to hang onto the broader
details of the approach (a string mixin or two isn't _that_
horrendous...) because there are some other aspects to it that I
would like to play with. But your suggested alternative is
interesting to consider.
Thanks very much for the useful ideas! :-)
More information about the Digitalmars-d-learn
mailing list