On 01/29/2012 12:44 PM, Philippe Sigaud wrote:
Hello,
I posted there a few weeks ago about a tutorial on D templates I put in github:
https://github.com/PhilippeSigaud/D-templates-tutorial/blob/master/dtemplates.pdf
Since then, I received numerous mails, issues, advices and thanks. Thank to you
all!
Following the ideas found in TDPL, I wrote a D script to extract and test all
the samples
presented in the document. I'm proud to say that right now, all named (module
XXX;) samples
compile, which makes for more than 200 modules tested! Indeed, you could see
the entire document
as a huge package documentation :)
I also added explanations, new sections and a new appendix in D templates
resources.
As before, do not hesitate to read, comment, post and even send pull requests,
I'm all ears.
Bye,
Philippe
First of all thank you so much for this wonderful book!
I would like to ask for a little enhancement regarding mixin templates.
see snippet.
The second mixin template "RandomAccessList" is slightly OT 'cause
Ranges are also touched, but I think this could be very interesting stuff.
A third mixin template example which comes in mind is the Publisher
subscriber pattern template.
snip.
import std.stdio;
import std.cstream;
void main(string[] args)
{
// showing mixin template scope.
auto bar = new Bar();
writeln(bar.onClick());
din.getc();
}
mixin template FooMixin()
{
void init()
{
}
string onClick()
{
return "Clicked";
}
}
class Foo
{
mixin FooMixin;
}
class Bar : Foo
{
}
// Something more interesting : Mixin templates and ranges
mixin template RandomAccessList()
{
alias typeof(this) Me;
//Either
static private Me[] MeArray;
//OR
private Me next, prev;
}
interface IRandomAccessRange {}
class Contacts : IRandomAccessRange // Contacts not Contact !
{
mixin RandomAccessList;
}