You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/** Initializes an object using a chain of method calls */structMethodInitializer(T) if (is(T ==class)) // currenly only works with classes
{
private T obj;
auto refopDispatch(string name)(typeof(__traits(getMember, T, name)) arg)
{
mixin("obj."~ name ~" = arg;");
returnthis;
}
}
/** Create an object using a chain of method calls for each field. */
T methodInit(T, alias Func, Args...)(Args args) if (is(T ==class)) // currently only works with classes
{
auto initializer = MethodInitializer!T(new T());
Func(initializer, initializer.obj, args);
initializer.obj.finalize();
return initializer.obj;
}
It turned out to be a nice syntax/mechanism for build.d. It almost emulates named parameter semantics. It allows
configuration in any order
cross-referencing data between fields
no need to modify surrounding lines to add/remove new configuration (don't have to worry about the comma , character to separate function arguments)
The text was updated successfully, but these errors were encountered:
In DMD I added an interesting way to initialize "make rules" in
build.d
(https://github.com/dlang/dmd/blob/master/src/build.d). here's an example:If reggae were to support the same syntax, the following:
could become:
The code to support the syntax is here:
It turned out to be a nice syntax/mechanism for
build.d
. It almost emulates named parameter semantics. It allows,
character to separate function arguments)The text was updated successfully, but these errors were encountered: