On Monday 30 August 2010 18:04:10 dsimcha wrote: > I've been toying for a long time with the idea of a std.mixins for Phobos > that would contain meta-implementations of commonly needed boilerplate > code for mixing into classes and and structs. I've started to prototype > it > (http://dsource.org/projects/scrapple/browser/trunk/std_mixins/std_mixins. > d). So far I have a mixin for struct comparisons, which is useful if you > need a total ordering for use with sorting or binary trees, but don't care > exactly how that ordering is defined. I've also got a mixin that converts > a class to a Singleton, and uses thread-safe but efficient mechanisms to > deal with the __gshared singleton case. > > I'm also thinking of creating some mixins to allow cloning of arbitrarily > complicated object graphs, provided that you don't stray outside of SafeD. > Is this worth implementing or will it likely be solved in some other way > at some point? > > Right now I'd just like to milk the D community for ideas. What other > pieces of boilerplate code do you find yourself writing often that the > standard library should help with?
The ones that I've wanted to implement but haven't yet (due to issues figuring out how to do them with __traits and std.traits) are opEquals(), opCmp(), and toHash(). Ideally, by default, they'd just process each of the member variables in lexical order (or whatever deterministic order you get them from __traits or std.traits), but you could give them a list of the member variables, and then only those member variables would be used, and they'd be used in the order that they were given. I figured that toHash() could use the hashing method described in Effective Java, since it seems solid, and that's what Apache uses for their function which generates a hash function (though, lacking all of D's compile- time code generation, their generative functions use reflection at runtime, which is obviously far less efficient). I'm willing to take a hack at implementing them again, but I'd given up with the idea of trying again when __traits and std.traits were more complete. - Jonathan M Davis