Dlang Features You Would Like To Share

Guillaume Piolat via Digitalmars-d digitalmars-d at puremagic.com
Thu Apr 13 04:14:28 PDT 2017


On Wednesday, 12 April 2017 at 21:40:48 UTC, bluecat wrote:
> What are some features that you have discovered that you would 
> like to share with the community? For me, one thing I found 
> interesting was the ability to define structures dynamically 
> using mixins:
>
> import std.stdio;
> import std.format: format;
>
> template MakePoint(string name, string x, string y) {
>     const char[] MakePoint = "struct %s {int %s; int 
> %s;}".format(name, x, y);
> }
>
> mixin(MakePoint!("Point", "x", "y"));
>
> void main() {
>     auto pt = new Point;
>     pt.x = 1;
>     pt.y = 2;
>     writefln("point at (%s, %s)", pt.x, pt.y);
> }

There are quite a few in https://p0nce.github.io/d-idioms/
and This Week in D: http://arsdnet.net/this-week-in-d/


More information about the Digitalmars-d mailing list