Hello list.

Probably there is a well-known answer to this but I failed to find it.

Native C glib states that a null pointer GList is a valid list and it can
be used as an argument to various list operations such as g_list_append().
And to check whether the list is empty you need just to compare the head of
the list with NULL;

But it's not that straightforward with vala. If I write:

var list = List<string>();

then vala generates something like:

GList * list = NULL;


And after that I can call some of methods of list (e.g.
list.append("hello");) but call to list.data would lead to a crash. That's
a bit strange but ok, I understand that functions able to operate null data
values like GList are not very well mapped to vala where this reference may
not be null.

The main question is when I have created list variable in vala, made some
insertions and deletions how do I check whether it is empty or not?
Probable answer would be I can call list.length(); method but it will not
be efficient if, say, I call it on every iteration of a loop and the list
is not empty.

Is there a more simple and efficient way?


BR, Vitaly Kirsanov
skype: vkirsan
_______________________________________________
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to