GNOME Bugzilla – Bug 531918
pair<T1,T2>
Last modified: 2019-03-20 10:35:56 UTC
I wish libgee/vala could have such a nice and useful type. Thanks!
public class Pair<T1,T2> { public T1 first; public T2 second; public Pair (T1# first, T2# second) { this.first = #first; this.second = #second; } } produces: OhmPair* ohm_pair_new (gpointer first, gpointer second) { OhmPair* self; gpointer _tmp1; gpointer _tmp0; gpointer _tmp3; gpointer _tmp2; self = g_slice_new0 (OhmPair); _tmp1 = NULL; _tmp0 = NULL; self->first = (_tmp1 = (_tmp0 = first, first = NULL, _tmp0), NULL, _tmp1); _tmp3 = NULL; _tmp2 = NULL; self->second = (_tmp3 = (_tmp2 = second, second = NULL, _tmp2), NULL, _tmp3); return self; } void ohm_pair_free (OhmPair* self) { NULL; NULL; g_slice_free (OhmPair, self); } Why first/second are not free'd?
I would like it to be a struct, unfortunately: I cannot use "this" in ctor, and the .vapi file does not have the template/generic arguments
(In reply to comment #1) > public class Pair<T1,T2> { > public T1 first; > public T2 second; > > public Pair (T1# first, T2# second) { > this.first = #first; > this.second = #second; > } > } > > produces: > OhmPair* ohm_pair_new (gpointer first, gpointer second) { > ... > } > > Why first/second are not free'd? > Just a guess, but type parameters being considered any gpointer, one cannot assume they are GObjects. More probable, ownership transfer on T1 and T2 shouldn't be possible, IMO.
Maybe we should better directly support tuples in Vala but not sure yet.
Please see also #597693
Moving this to libgee as we can't really add types in the compiler. For tuples, see bug 597693.
public class Pair<T1,T2> { public T1 first; public T2 second; public Pair (T1 first, T2 second) { this.first = first; this.second = second; } } Seems to work well enough nowadays (no need for ownership transfer).
Can we apply that? What about triplets and quadruples?
*** Bug 589801 has been marked as a duplicate of this bug. ***
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/libgee/issues/2.