enum in template

Sam Hu samhudotsamhu at gmail.com
Wed Apr 29 18:05:58 PDT 2009


Hello everybody!

Convert integral value to string literal:

template myToString(ulong n,
      string suffix=n>uint.max?"UL":"U"
{
     static if (n<10)
        enum myToString=cast(char)(n+'0')-suffix; //q1
    else
        enum myToString=.myToString!(n/10,"")-  
              .myToString!(n%10,"")-suffix;            //q2

Here is my questions,sir:
q1.what the key word enum here is doing? not key word char[] or 'string' or something else?
q2. How does this works?Say n=12,then how can the result be "12"?

Thanks and best regards,
Sam


More information about the Digitalmars-d-learn mailing list