std.mixins

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Aug 30 20:20:54 PDT 2010


On 8/30/10 20:04 PDT, 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.

Upon a second look I think the Singleton implementation is not up to 
snuff and reflects a common misunderstanding of the pattern.

The point of the Singleton is that you can instantiate it with a derived 
class. Otherwise, it's the less interesting Monostate pattern. The code 
as is right now uses hardcoded calls to new, and it shouldn't.


Andrei


More information about the Digitalmars-d mailing list