You can create an empty list with the default constructor. The C version returns a handler on the list.
C++ : template <class T> TCODList::TCODList()
C : TCOD_list_t TCOD_list_new()
Example :
C++ : TCODList<int> intList;
TCODList<float> *floatList = new TCODList<float>();
C : TCOD_list_t intList = TCOD_list_new();
TCOD_list_t floatList = TCOD_list_new();
You can also create a list by duplicating an existing list.
C++ : template <class T> TCODList::TCODList(const TCODList &l)
C : TCOD_list_t TCOD_list_duplicate(TCOD_list_t l)
Parameter | Description |
l | Existing list to duplicate. |
Example :
C++ : TCODList<int> intList;
intList.push(3);
intList.push(5);
TCODList<int> intList2(intList); // intList2 contains two elements : 3 and 5
C : TCOD_list_t intList = TCOD_list_new();
TCOD_list_push(intList,(const void *)3);
TCOD_list_push(intList,(const void *)5);
TCOD_list_t intList2 = TCOD_list_duplicate(intList); /* intList2 contains two elements : 3 and 5 */
You can also create an empty list and pre-allocate memory for elements. Use this if you know the list size and want the memory to fit it perfectly.
C++ : template <class T> TCODList::TCODList(int nbElements)
C : TCOD_list_t TCOD_list_allocate(int nbElements)
Parameter | Description |
nbElements | Allocate memory for nbElements. |
Example :
C++ : TCODList<int> intList(5); // create an empty list, pre-allocate memory for 5 elements
C : TCOD_list_t intList = TCOD_list_allocate(5);