www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - static opIndex not working with templated class

reply Ivan Senji <ivan.senji_REMOVE_ _THIS__gmail.com> writes:
Given this code:

class array(T)
{
   static T[] opIndex(T[] a ...)
   {
     return a.dup;
   }
}

This doesn't work:

float[] a = array!(float)[1,2,3];

DMD(0.135) Compiler complains:

animacija.d(48): only one index allowed to index void
animacija.d(48): class array must be an array or pointer type, not void
animacija.d(48): cannot implicitly convert expression (class array[1]) 
of type int to float[]

But this works:

alias array!(float) type;
float[] a = type[1,2,3];
Oct 24 2005
parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ivan Senji schrieb am 2005-10-24:
 Given this code:

 class array(T)
 {
    static T[] opIndex(T[] a ...)
    {
      return a.dup;
    }
 }

 This doesn't work:

 float[] a = array!(float)[1,2,3];

 DMD(0.135) Compiler complains:

 animacija.d(48): only one index allowed to index void
 animacija.d(48): class array must be an array or pointer type, not void
 animacija.d(48): cannot implicitly convert expression (class array[1]) 
 of type int to float[]

 But this works:

 alias array!(float) type;
 float[] a = type[1,2,3];

Added to DStress as http://dstress.kuehne.cn/run/t/template_class_11_A.d http://dstress.kuehne.cn/run/t/template_class_11_B.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFDYi3n3w+/yD4P9tIRAtkeAJ9SQi7cpQLT4xFL96EeiI3t4D+ZhgCfXDml 6tdP+9z+ij9vJafDq8+UV8I= =Rscr -----END PGP SIGNATURE-----
Oct 28 2005