some mixin utilities

Tobias Pankrath lists at pankrath.net
Mon Nov 5 10:52:02 PST 2012


On 05.11.2012 18:30, Dan wrote:
> I've created some mixins that I think will help me with structs, and
> being new to D would like some constructive criticism/suggestions on the
> code. The code is at
> https://github.com/patefacio/d-help/blob/master/d-help/opmix/mix.d
>
> Some questions:
> - I have done a bit of casting in a few places and would like to know if
> they are safe.
> - I'm no hashing expert so any suggestions on approach appreciated.
> - If mixin(Dup) encounters a plain pointer and it can create a target on
> the heap it does. Is this safe?
> - The focus is structs because for now I'm afraid of classes. Could they
> be incorporated or would that be a can of worms?
>
> Hopefully the comments convey the intent well enough and if there are
> better approaches please let me know.
> Any feedback appreciated.
>
> Thanks
> Dan

I like the general style. However this provokes a invinite loop:
-----
struct A
{
         A* other;
}

import std.stdio;

void main()
{
         A a, b;
         b.other = &a;
         a.other = &b;
         writeln(typesDeepEqual(a, b));
}
-----

And I would find the comparison more useful, if it uses the user defined 
opEquals for a field if there is one.





More information about the Digitalmars-d-learn mailing list