Dlang Features You Would Like To Share

bluecat via Digitalmars-d digitalmars-d at puremagic.com
Wed Apr 12 14:40:48 PDT 2017


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);
}


More information about the Digitalmars-d mailing list