Commits

Niklas Frykholm  committed 76c9cbd

Added clear(), trim(), reserve()

  • Participants
  • Parent commits d274669

Comments (0)

Files changed (2)

 
 #include <memory>
 
+// TODO:
+// * insert
+// * erase
+
 namespace array
 {
 	template<typename T> inline uint32_t size(const Array<T> &a) 		{return a._size;}
 	template<typename T> inline T& back(Array<T> &a) 					{return a._data[a._size-1];}
 	template<typename T> inline const T& back(const Array<T> &a) 		{return a._data[a._size-1];}
 
+	template <typename T> inline void clear(Array<T> &a) {resize(a,0);}
+	template <typename T> inline void trim(Array<T> &a) {set_capacity(a,a._size);}
+
 	template <typename T> void resize(Array<T> &a, uint32_t new_size)
 	{
 		if (new_size > a._capacity)
 		a._size = new_size;
 	}
 
+	template <typename T> inline void reserve(Array<T> &a, uint32_t new_capacity)
+	{
+		if (new_capacity > a._capacity)
+			set_capacity(a, new_capacity);
+	}
+
 	template<typename T> void set_capacity(Array<T> &a, uint32_t new_capacity)
 	{
 		if (new_capacity == a._capacity)

File collection_types.h

 #include "types.h"
 #include "memory_types.h"
 
+/// Array of POD objects.
+/// * Does not call constructors & destructors on elements.
+/// * Assumes they can be moved with memmove().
 template<typename T> struct Array
 {
 	Array(Allocator &a);