> That being said, I have never used CRTP in D so far, since template mixins seem to be the better choice in almost all situations.
FWIW, CRTP is the main reason I used classes in Pegged, to allow grammar rules to refer to themselves. My earlier attempts with structs did not work.
So, given a grammar rule like:
Expr <- '(' Expr ')' / ...
I use:
class Expr : Or! (Sequence!(Literal!("("), Expr, Literal!(")")) , ...)
{ ... }
As you can see, class Expr refer to itself while it's not defined yet. It's the main use I've found for this idiom. Many C++ parsers use the same trick and I was particularly glad to see it worked in D too.
Most of the times I use mixins, but could not find a way to do the same recursive rule definition with them.
IIRC, I talk a bit about the CRTP in my tutorial on D templates , on Github.
Philippe