Re: [Vala] int64 generics



using Gee;

public int compare_func(int64? a, int64? b)
{
    if (a > b) return 1;
    if (a < b) return -1;
    return 0;
}

public bool equal_func(int64? a, int64? b)
{
    return a == b;
}

int main()
{
    var ar = new ArrayList<int64?>((EqualFunc)equal_func);
    ar.add((int64)1);
    ar.add((int64)2);
    ar.add((int64)4);
    ar.add((int64)3);
    ar.sort((CompareFunc)compare_func);
    foreach (int64? i in ar) stdout.printf(@"$((int64)i)\n");
    return 0;
}


On Wed, Aug 3, 2011 at 1:23 AM, rastersoft <raster rastersoft com> wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi all:

I need to create an ArrayList with int64 values. Using

   var mylist = new ArrayList<int64>();

returns an error: int64 is not a supported generic type argument, use
? to box value types

I box it with

   var mylist = new ArrayList<int64?>();

and compiles, but the sort() function works incorrectly. I created my
own compare function, but the results are exactly the same.

   public static int mysort(int64? a, int64? b) {
       if(a>=b) {
           return 1;
       } else {
           return 0;
       }
   }

(I tested both with int64 and int64? in the params, but is the same).

How can I do it?

Thanks.

- --
Nos leemos
                RASTER    (Linux user #228804)
raster rastersoft com              http://www.rastersoft.com

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk44hv8ACgkQXEZvyfy1ha9zCACbBHxxZKJWb9GqLRPl9e7PWr/q
KOMAoJujz8PSjiHtldBDMLRH/RTFfktZ
=6maQ
-----END PGP SIGNATURE-----

_______________________________________________
vala-list mailing list
vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]