How to use "Template Constructors" in D? -


the template documentation d includes small section called "template constructors". section doesn't have example or extensive documentation.

i'm attempting use feature (i'm aware use "static constructor", have reasons prefer template constructor).

particularly, i'm attempting generate hashes @ compile time. here's attempt:

struct myhash {     uint value;      this(uint value)     {         this.value = value;     }      this(string str)()     {         enum h = myhashfunc(str);         return myhash(h);     } }  uint myhashfunc(string s) {     // hashing implementation     return 0; }  int main(string[] str) {     myhash x = myhash!"helloworld";     return 0; } 

this doesn't compile dmd 2.053:

x.d(10): error: template x.myhash.__ctor(string str) conflicts constructor x.myhash.this @ x.d(5) 

it complains first constructor. after removing it:

x.d(20): error: template instance myhash not template declaration, struct 

which pretty logical, considering syntax use same if myhash template structure.

so, know how can declare , call "template constructor"?

i asked around on irc, , far can figure out never implemented d1, we're guessing it's still unimplemented. furthermore, there no mention of feature in the d programming language, whole thing in air bit.

if you, submit bug against documentation.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -