www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - . is still required for recursion when a template alias is used.

reply Don Clugston <dac nospam.com.au> writes:
If you insert a dot before the recursive factorial call,
it will work correctly.

-----------
template factorial(int n)
{
   static if (n<2) const int factorial = 1;
   else const int factorial = n * factorial!(n-1);
}

template rhino(alias hippo)
{
   const int rhino = hippo!(2);
}

const int lion = rhino!(factorial);
--------------
Jan 25 2006
parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Don Clugston schrieb am 2006-01-25:
 If you insert a dot before the recursive factorial call,
 it will work correctly.

 -----------
 template factorial(int n)
 {
    static if (n<2) const int factorial = 1;
    else const int factorial = n * factorial!(n-1);
 }

 template rhino(alias hippo)
 {
    const int rhino = hippo!(2);
 }

 const int lion = rhino!(factorial);
 --------------

Added to DStress as http://dstress.kuehne.cn/run/t/template_26_A.d http://dstress.kuehne.cn/run/t/template_26_B.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFD5bZO3w+/yD4P9tIRAuTmAJ4/CgyPtPApqw119oJwJTYaRwJS0gCgrqB0 jrijOw1cOV9NAsuv9ZdIBsY= =RCJP -----END PGP SIGNATURE-----
Feb 05 2006