Idea to improve support for generics



I thought it would be a nice idea to map gpointer arguments and return values etc to generics/templates in languages that support them, with wrappers for actual functions and using generics directly for callbacks. But then I noticed I'm getting things like this (for a Kotlin native version of GCompareFunc):

typealias CompareFunc<in T1, in T2> = (a: T1?, b: T2?) -> Int

a and b should be the same type, so it would be better as:

typealias CompareFunc<in T1> = (a: T1?, b: T1?) -> Int

However, there are other cases, such as GCopyFunc, where there are two gpointer arguments that can't be assumed to be the same type, but the return value should be the same type as the first input. Currently there's no way of detecting these situations, so I either have to stick to the first form or write overrides by hand.

Wouldn't it be a good idea to add an annotation and corresponding typelib and gir representations for this? For the annotation I'm thinking along the lines of (generic 0), meaning the argument or return value with this annotation should have the same type as argument 0. Perhaps it would also be a good idea to have some way of saying that a gpointer shouldn't be mapped to a generic, but I would prefer the default to be that gpointer does imply generic.

--
TH



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