5#include <initializer_list>
10#include "arrayLike.hpp"
13#include "typeChecks.hpp"
16#if __has_include(<cereal/cereal.hpp>)
17#include <cereal/archives/json.hpp>
18#include <cereal/archives/xml.hpp>
56 template <
typename...
Args>
132 template <
typename...
Args>
171 virtual int add(
const T &
object) {
205 inline int push(
const T &
object)
noexcept {
233 throw std::out_of_range(
"No more elements in array.");
326 virtual int find(
const T &
object)
const {
344 return find(
object) > -1;
363 void sort(std::function<
bool(
const T &,
const T &)> lambda)
noexcept {
388 array sorted(std::function<
bool(
const T &,
const T &)> lambda)
const noexcept {
401 std::random_device device;
428 for (
int i = 0;
i < (
len / 2); ++
i) {
498 template <
typename U>
530 template <
typename U>
540 template <
typename U>
580 throw std::out_of_range(
"Array is empty");
583 std::random_device device;
604 std::random_device device;
644#if __has_include(<cereal/cereal.hpp>)
649 void save(cereal::JSONOutputArchive &
ar)
const {
660 void save(cereal::XMLOutputArchive &
ar)
const {
670 template <
typename archive>
682 void load(cereal::JSONInputArchive &
ar) {
688 for (
int i = 0;
i <
sz;
i++) {
698 void load(cereal::XMLInputArchive &
ar) {
714 template <
class archive>
743template <
typename...
Args>
1008 end = index + count;
1010 start = index + count + 1;
1029template <
typename T>
1040template <
typename T>
1057template <
typename T>
1074template <
typename T>
1090template <
typename T>
1104 end = index + count;
1106 start = index + count + 1;
1137template <
typename T>
1147 end = index + count;
1149 start = index + count + 1;
1171template <
typename T>
1187 end = index + count;
1189 start = index + count + 1;
1203 if (
end - start > 0) {
1206 for (
int i = start;
i <
end;
i++) {
1213template <
typename T>
1218template <
typename T>
1226template <
typename T>
1234template <
typename T>
1235template <
typename U>
1247template <
typename T>
1261template <
typename T>
1269 for (
int i = 1;
i <
len; ++
i) {
1279#define zarray z::core::array
An interface for all objects that can be both iterated over and directly indexed.
Definition arrayLike.hpp:13
A wrapper for std::vector.
Definition array.hpp:38
bool isValid(int index) const
Check if an index is within the bounds of the array.
Definition array.hpp:1219
void increase(int newSize) noexcept
Increase the space allocated for this array.
Definition array.hpp:155
int push(const T &object) noexcept
Add an object to the array.
Definition array.hpp:205
virtual bool eq(const T &arg1, const T &arg2) const
Check if two objects are equal.
Definition array.hpp:74
bool contains(const T &object) const noexcept
Check if a given object is in the array.
Definition array.hpp:343
bool operator>(const array &other) const
Array greater-than operator.
Definition array.hpp:822
array filter(std::function< bool(const T &)> lambda) const
Filters the array based on a predicate and returns a new array containing the elements that satisfy t...
Definition array.hpp:1248
array(const array &other)
Copy constructor.
Definition array.hpp:733
virtual void shuffle() noexcept
Shuffle the elements of the array into a random order.
Definition array.hpp:400
void sort(std::function< bool(const T &, const T &)> lambda) noexcept
Sort the array based on an arbitrary function.
Definition array.hpp:363
array< U > operator|(U(*lambda)(T)) noexcept
Definition array.hpp:541
array sorted() const noexcept
Sort the array based on default comparison operator.
Definition array.hpp:374
void init(const T &arg1)
Helper function for single object initialization.
Definition array.hpp:47
virtual int find(const T &object) const
Find the index of a given object in the array.
Definition array.hpp:326
void add(const array &other) noexcept
Add another array to this array.
Definition array.hpp:187
array sorted(std::function< bool(const T &, const T &)> lambda) const noexcept
Sort the array based on an arbitrary function.
Definition array.hpp:388
std::vector< T > array_data
The data in the array.
Definition array.hpp:41
array & operator=(const std::initializer_list< T > &other)
Initializer list assignment operator.
Definition array.hpp:778
array(const T &arg1, const Args &...args)
List-initialized constructor.
Definition array.hpp:744
void sort() noexcept
Sort the array based on default comparison operator.
Definition array.hpp:352
bool operator<=(const array &other) const
Array less-than-or-equal operator.
Definition array.hpp:906
array & operator=(const array &other)
Array assignment operator.
Definition array.hpp:760
bool operator!=(const array &other) const
Check whether two arrays' contents are different.
Definition array.hpp:878
T & operator[](int index)
Function to get the object at the given index.
Definition array.hpp:311
size_t size() const noexcept override
Get the size of the array.
Definition array.hpp:1030
array()
Default constructor.
Definition array.hpp:112
int length() const noexcept override
Get the length of the array.
Definition array.hpp:1041
array shuffled() const noexcept
Shuffle the elements of the array into a random order.
Definition array.hpp:414
array & insert(const T &, int)
Insert an object into the array.
Definition array.hpp:929
virtual bool operator()(const T &arg1, const T &arg2) const
Callable operator.
Definition array.hpp:1214
bool operator<(const array &other) const
Array less-than operator.
Definition array.hpp:850
array randomElements(int count) const noexcept
Get N random elements from the array.
Definition array.hpp:599
array reversed() const noexcept
Reverse the order of all elements in the array.
Definition array.hpp:441
T & at(int)
Function to get the object at the given index.
Definition array.hpp:1058
void init(const T &arg1, const Args &...args)
Helper function for brace-enclosed list initialization.
Definition array.hpp:57
T randomElement() const
Get a random element from the array.
Definition array.hpp:578
void push(const array &other) noexcept
Add another array to this array.
Definition array.hpp:219
T operator>>(std::function< T(const T &, const T &)> lambda)
Reduces the array to a single value by applying a binary operation cumulatively to the elements.
Definition array.hpp:565
array & replace(int, int, const T &)
Replace all objects in the given range with an object.
Definition array.hpp:1091
array(const std::vector< T > &other)
Copy from std::vector.
Definition array.hpp:738
void append(const T &)
Append an object to the end of the array.
Definition array.hpp:961
array & remove(int)
Remove an object from the array.
Definition array.hpp:973
virtual ~array()
Destructor.
Definition array.hpp:143
bool operator>=(const array &other) const
Array greater-than-or-equal operator.
Definition array.hpp:892
virtual void reverse() noexcept
Reverse the order of all elements in the array.
Definition array.hpp:426
array & replace(int, int, const array< T > &)
Replace all objects in the given range with an array of objects.
Definition array.hpp:1138
virtual int add(const T &object)
Add an object to the array.
Definition array.hpp:171
array operator&&(std::function< T(const T &)> lambda) noexcept
Definition array.hpp:550
virtual bool gt(const T &arg1, const T &arg2) const
Check if one object is greater than another.
Definition array.hpp:90
array< U > operator|(std::function< U(T)> lambda) noexcept
Definition array.hpp:531
array(const std::initializer_list< T > &other)
Construct from a generic initializer list.
Definition array.hpp:140
array subset(int index, int count) const
Get a contiguous subset of the elements in the array.
Definition array.hpp:1172
T reduce(std::function< T(const T &, const T &)> lambda, const T &defaultValue={}) const
Reduces the array to a single value by applying a binary operation cumulatively to the elements.
Definition array.hpp:1262
array & remove(int, int)
Remove all elements in a subset of the array.
Definition array.hpp:995
T * begin() const noexcept override
Get pointer to the beginning of the array.
Definition array.hpp:627
virtual bool lt(const T &arg1, const T &arg2) const
Check if one object is less than another.
Definition array.hpp:106
T * end() const noexcept override
Get pointer to the end of the array.
Definition array.hpp:639
bool operator==(const array &other) const
Check whether two arrays' contents are the same.
Definition array.hpp:798
array< U > map(std::function< U(const T &)> lambda) const
Applies a transformation function to each element of the array and returns a new array with the resul...
Definition array.hpp:1236
array & swap(int index1, int index2)
Swap two elements in an array.
Definition array.hpp:1227
void clear()
Clear the data in the array.
Definition array.hpp:912
T pop()
Remove the last element from this array.
Definition array.hpp:231
An arbitrary generator for producing sequential results on-the-fly.
Definition generator.hpp:71
An interface for getting an object's size.
Definition sizable.hpp:13
std::enable_if< std::is_base_of< z::core::sizable, T >::value >::type size(const T &object, size_t &bytes) noexcept
Get the size of a sizable object.
Definition sizable.hpp:31