-
Notifications
You must be signed in to change notification settings - Fork 5
C++ Array
An Array takes ownership over some arbitrary C array and frees its memory in the destructor. The memory of the C array NEEDS to be allocated by malloc, calloc, realloc or reallocarray!
static Array<T> New(size_t size);
Allocates memory and creates a new array with it.
- size Number of elements of the new array
Array() noexcept;
Array(T *data, size_t size, bool delete_data = true) noexcept;
Array(Array<T> &&rhs) noexcept;
Array(const Array<T> &rhs) = delete;
Array<T> &operator=(Array<T> &&rhs) noexcept;
When constructing a new array it takes ownership over some C array. Only move semantics are allowed.
- data An C array allocated by malloc, calloc, realloc or reallocarray
- size The number of elements inside data
- delete_data Wether to free data in the destructor
T &operator[](size_t index);
const T &operator[](size_t index) const;
- index Which element to return
bool operator==(const char *str2) const noexcept;
bool operator==(const std::string &str2) const noexcept;
bool operator==(const Array<T> &rhs) const noexcept;
Equality against a string can be checked only if the array itself can be considered a string.
T *data() noexcept;
const T *data() const noexcept;
Returns the raw pointer to the underlying C array.
size_t size() const noexcept;
Returns the number of elements in the array.
bool empty() const noexcept;
Returns wether no elements are in the array.
std::string str() const noexcept;
Converts the array to a string. Works only with uint8_t, int8_t and char.
Iterator begin() noexcept;
Iterator end() noexcept;
ConstIterator begin() const noexcept;
ConstIterator end() const noexcept;
The Array can be iterated in a foreach loop.
This is a null terminated string of char.
String(char *str, bool delete_data = true) noexcept;
Create a String from a C string.
- str The C string. If delete_data is true it must be allocated by either malloc, calloc, realloc or reallocarray.
- delete_data Wether to delete str in the destructor
This is a sized string of char. Which means that it does not necessarily end with a null terminator.