Gtk toArray List funkiness
Joseph via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Sep 16 18:58:30 UTC 2017
https://github.com/gtkd-developers/GtkD/blob/master/demos/gtkD/TestWindow/TestWindow.d
has the code
foreach ( int i, string selection ; fs.getSelections())
{
writeln("File(s) selected [%d] %s",i,selection);
}
which is invalid for the demo, but
foreach ( int i, string selection ;
fd.getFilenames().toArray!(string,?))
{
writeln("File(s) selected [%d] %s",i,selection);
}
results in some funky code. Gives errors in ObjectG about uint
when setting ? to string, string* or void* or even uint:
GtkD\generated\gtkd\gobject\ObjectG.d(172): Error: incompatible
types for ((obj) is (null)): 'uint' and 'typeof(null)'
GtkD\generated\gtkd\glib\ListSG.d(98): Error: template instance
gobject.ObjectG.ObjectG.getDObject!(string, string, uint) error
instantiating
test.d(91): instantiated from here: toArray!(string, uint)
test.d(93): Error: invalid foreach aggregate `fd.getFilenames()`,
define opApply(), range primitives, or use .tupleof
without specifying ? it assumes it's a tuple, which seems wrong?
public T[] toArray(T, TC = typeof(T.tupleof[0]))()
{
T[] arr = new T[length()];
ListSG list = this;
size_t count;
while(list !is null && count < arr.length)
{
arr[count] = ObjectG.getDObject!(T)(cast(TC)list.data);
list = list.next();
count++;
}
return arr;
}
foreach ( int i, Value selection ;
fd.getFilenames().toArray!(Value)())
{
writeln("File(s) selected [%d] %s",i,selection.getString);
}
crashes ;/
I'm not sure what types are what and it changes depending on the
input. I think Value is the wrong type to use but string doesn't
work so...
More information about the Digitalmars-d-learn
mailing list