std.mixins
Lutger
lutger.blijdestijn at gmail.com
Tue Aug 31 10:45:37 PDT 2010
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?
Instead of std.mixins, perhaps it is better to fold the code with std.typecons
or create new modules as needed (std.pattern?). There is also some private
boilerplate code here and there in phobos that help with ctfe and
metaprogramming, some people may also find that useful if packaged as a seperate
utility module.
My suggestion is to include a mixin for unrolling loops. Also something like
defineEnum, but for generating bitflags. (I have some code for this). I would
also like to see a mixin for generating the boilerplate for decorator
forwarding, which is annoying. This should be not that hard with the existing
code in std.typecons.
Furthermore (not mixin related perse) more phobos code could be made to work at
compile time. I am pleasantly surprised a lot has improved in this respect the
last few releases, but more can be done (sorting for example is useful and
possible). The dranges project at dsource is awesome, it wouldn't hurt to put
some of that good stuff in phobos.
More information about the Digitalmars-d
mailing list