fbList is an easy to use, fast, arbitrary index, type-agnostic, extensible, and sortable list library
Code: Select all
'// Typelist example
#include once "../fbList.bi"
'// TypeList's are where fbList really shines by enabling the creation of
'// fast arbitrary strongly typed lists of any type, including user defined.
print "The TYPELIST <listname> HOLDS <listtype> macro allows the easy"
print " creation of lists containing any type, including user defined ones."
'// Create an array of numbers
dim as integer ScrambledNumbers(...) = {5, 1, 3, 4, 2}
'// Create a new list type named IntList that can hold integers
TypeList IntList Holds integer
'// Create a list off of our TYPELIST and fill it with the numbers we defined above
dim as IntList myList = ScrambledNumbers()
print "myList is "& myList.Length &" items long:"
myList.ForEach(i as integer)
if i > 0 then
print ", "& myList[i];
else
print " "& myList[i];
end if
next
print
myList += 99 '// += is shorthand to Insert a new element at the end of the list
print " After +=, myList is "& myList.Length &" items long:"
print " "& myList.CSV() '// .CSV returns a comma separated string of all elements in the list
myList.Remove(2) '// Remove the element at index 2
print " After .Remove(2), myList is "& myList.Length &" items long:"
print " "& myList.CSV() '// .CSV returns a comma separated string of all elements in the list
myList.Insert(3, 2) '// Insert the element 3 at index 2
print " After .Insert(3,2), myList is "& myList.Length &" items long:"
print " "& myList.CSV() '// .CSV returns a comma separated string of all elements in the list
print
print "Press any key to close the example!"
sleep
Details:
- Language: FreeBASIC
- Library type: .bi header
- Attribution: fbList is Copyright (c) 2023-2024 Johannes "Jattenalle" Pihl, all rights reserved
- Sourcecode: Yes, zLib license