On Saturday, 30 July 2016 at 22:05:29 UTC, cym13 wrote:
On Saturday, 30 July 2016 at 21:45:31 UTC, Cauterite wrote:
On Saturday, 30 July 2016 at 21:42:42 UTC, cym13 wrote:
...
Here's something you might enjoy in the meantime:
https://github.com/Cauterite/dlang-pod-literals/blob/master/podliterals.d
Thanks, I'm aware of this work but some points just aren't good
enough IMHO. We can do better than that. First of all the
syntax is too far appart from traditional field assignment
which is always done using ':' . I understand why it is so but
still it makes one more thing to remember. Calling lambdas all
the time isn't free while the change I propose is static. Those
lambdas aren't optimized away by DMD and while that might
change I just don't feel like trusting it. And more importantly
it doesn't work with common structs, you have to pass it to
your template first and then it isn't the struct anymore. There
are just too many ways for this to get wrong in my opinion.
Note that I find the idea ingenious and interesting, I just
think we can do better than that.
It does work with common structs:
struct Xyzº {
int X;
wstring Y;
Object Z;
};
auto Thing = pod!(Xyzº,
Y => `asdf`w,
X => 3,
Z => null,
);
assert(is(typeof(Thing) == Xyzº));
But anyway, you don't need to convince me that having a native
language feature would be superior to this template nonsense :P
It's just a workaround for the moment (albeit a bloody powerful
workaround!)
Although I do like being able to both define and instanciate a
structure in the same expression (especially with unions). Maybe
that could be a future extension to your DIP.