I want to add a Phobos module with template mixins for common idioms.

Idan Arye GenericNPC at gmail.com
Fri May 24 13:26:11 PDT 2013


On Friday, 24 May 2013 at 13:43:02 UTC, Dmitry Olshansky wrote:
> I've found github pages to be just fine.

Then GitHub pages it is - 
http://someboddy.github.io/phobos/ddocs/for-idioms/idioms.html

I've also added this link to the pull request and to the review 
queue.

> Turns out that doing shared classes (and singletons conversely) 
> has one big of disadvantage: you can't have TLS reference to 
> shared class instance (ditto with mutable reference to const 
> object).
>
> It's a well-known problem of the way OOP is done in D - object 
> and reference to it are tightly coupled and qualifier applies 
> transitively to both.
>
> There was a pull that allowed to separate qualifier of instance 
> from reference (handle) looking like this:
>
> ref const(Object) refToConst;
>
> ref Object mutableTlsRef;
> Object mutableTlsRef; //same as above
>
> ref const Object constRefToConst;
> const Object constRefToConst; //ditto
>
> The fact that we don't have it is part of the reason I don't 
> like doing OOP in D at all.

Like Jonathan M Davis said, it could easily be added as a class. 
This is another example to D's flexibility - the ability to 
implement such things without changing the compiler. But still - 
a thing like this should be part of the language itself.

Anyways, since the implementation is so easy and short I could 
tweet it, I see no reason why not to make a pull request. It's 
gonna be in `std.typecons`, not in `std.idioms`, so I'll wait 
with using it in `std.idioms` until it gets pulled - or gets 
rejected in favor of a better(dmd) solution.


More information about the Digitalmars-d mailing list