Recursive template
    Chris Nicholson-Sauls via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Sat Nov 15 18:54:45 PST 2014
    
    
  
Slightly simpler:
struct SomeType(K, V) {}
alias X(V)       = V;
alias X(V, K...) = SomeType!(K[0], X!(V, K[1 .. $]));
That's a recurring pattern to get used to: aliasing away to one 
of the parameters in a terminal and/or degenerate case.  Also: 
that an empty tuple matches no parameter "more exactly" than a 
tuple parameter.  I know that's not at all obvious, but it's what 
I've found to be the case; so when K[1 ..$] above ends up as the 
empty tuple (that is, when all K have been exhausted), the 
template for X(V) will be the "more exact match."
    
    
More information about the Digitalmars-d-learn
mailing list