On Friday, 15 May 2015 at 12:22:55 UTC, Artur Skawina wrote:
template let(string D) {
mixin({
enum sdsl = D.findSplit("=");
mixin(`struct S { int `~sdsl[0]~`; }`);
string code = `auto v = ` ~ sdsl[2] ~ `;`;
foreach (I, _; typeof(S.tupleof))
code ~= `auto ` ~ S.tupleof[I].stringof ~ ` =
v[`~I.stringof~`]; `;
return code;
}());
}
I added support for auto, const and immutable declarations at
https://github.com/nordlow/justd/blob/master/ties.d#L96
which allows usage as
mixin let!q{ auto i, d, s, c = tuple(42, 3.14, `pi`, 'x') };
mixin let!q{ const i, d, s, c = tuple(42, 3.14, `pi`, 'x') };
mixin let!q{ immutable i, d, s, c = tuple(42, 3.14, `pi`,
'x') };
:)
See unittests for details