2023-01-18 10:49:32 +00:00
|
|
|
|
/***
|
2022-04-01 04:06:53 +00:00
|
|
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
|
|
File: auArray.hpp
|
|
|
|
|
Date: 2022-2-1
|
|
|
|
|
Author: Reece
|
|
|
|
|
***/
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2023-01-18 10:49:32 +00:00
|
|
|
|
#if defined(_AURORA_AVOID_EXTREMLY_DUMB_STL_TYPES) && !defined(_AURORA_FORCE_STD_ARRAY)
|
2023-01-18 16:29:35 +00:00
|
|
|
|
|
|
|
|
|
// following the conventions set out in other out of ecosystem macro-test cases for identifying aurora types in portable header libraries
|
|
|
|
|
#define AU_AuArray AuArray
|
|
|
|
|
|
2023-01-18 10:49:32 +00:00
|
|
|
|
template <class T, size_t Count>
|
|
|
|
|
struct AuArray
|
|
|
|
|
{
|
|
|
|
|
T elements[Count] {};
|
|
|
|
|
|
|
|
|
|
static const AuUInt kElementCount = Count;
|
|
|
|
|
|
2024-09-01 18:43:22 +00:00
|
|
|
|
using value_type = T;
|
2023-01-18 10:49:32 +00:00
|
|
|
|
|
2024-09-01 18:43:22 +00:00
|
|
|
|
using size_type = AuUInt;
|
|
|
|
|
using difference_type = AuSInt;
|
2023-01-18 10:49:32 +00:00
|
|
|
|
|
2024-09-01 18:43:22 +00:00
|
|
|
|
using pointer = value_type *;
|
|
|
|
|
using const_pointer = const value_type *;
|
2023-01-18 10:49:32 +00:00
|
|
|
|
|
2024-09-01 18:43:22 +00:00
|
|
|
|
using reference = value_type &;
|
|
|
|
|
using const_reference = const value_type &;
|
2023-01-18 10:49:32 +00:00
|
|
|
|
|
2024-09-01 18:43:22 +00:00
|
|
|
|
using iterator = pointer;
|
|
|
|
|
using const_iterator = const_pointer;
|
|
|
|
|
|
|
|
|
|
using reverse_iterator = AuReverseIterator<iterator>;
|
|
|
|
|
using const_reverse_iterator = AuReverseIterator<const_iterator>;
|
2023-01-18 10:49:32 +00:00
|
|
|
|
|
|
|
|
|
void fill(const T &value)
|
|
|
|
|
{
|
|
|
|
|
if constexpr (AuIsSame_v<T, AuUInt8> || AuIsSame_v<T, AuInt8>)
|
|
|
|
|
{
|
|
|
|
|
AuMemset(this->elements, value, sizeof(this->elements));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (AU_ITERATE_N(i, kElementCount))
|
|
|
|
|
{
|
|
|
|
|
this->elements[i] = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-01 18:43:22 +00:00
|
|
|
|
void Fill(const T &value)
|
|
|
|
|
{
|
|
|
|
|
this->fill(value);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-18 10:49:32 +00:00
|
|
|
|
void swap(AuArray &other)
|
|
|
|
|
{
|
|
|
|
|
AuArray temp;
|
|
|
|
|
|
2024-09-01 18:43:22 +00:00
|
|
|
|
if constexpr (AuIsTriviallyCopyable_v<T>)
|
2023-01-18 10:49:32 +00:00
|
|
|
|
{
|
|
|
|
|
AuMemcpy(temp, this->elements, sizeof(this->elements));
|
|
|
|
|
AuMemcpy(this->elements, other.elements, sizeof(this->elements));
|
|
|
|
|
AuMemcpy(other.elements, temp, sizeof(this->elements));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
AuArray temp;
|
|
|
|
|
for (AU_ITERATE_N(i, kElementCount))
|
|
|
|
|
{
|
|
|
|
|
temp[i] = this->elements[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (AU_ITERATE_N(i, kElementCount))
|
|
|
|
|
{
|
|
|
|
|
this->elements[i] = other.elements[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (AU_ITERATE_N(i, kElementCount))
|
|
|
|
|
{
|
|
|
|
|
other.elements[i] = temp[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-01 18:43:22 +00:00
|
|
|
|
|
|
|
|
|
void Swap(AuArray &other)
|
|
|
|
|
{
|
|
|
|
|
this->swap(other);
|
|
|
|
|
}
|
2023-01-18 10:49:32 +00:00
|
|
|
|
|
|
|
|
|
constexpr iterator begin()
|
|
|
|
|
{
|
|
|
|
|
return this->elements;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr const_iterator begin() const
|
|
|
|
|
{
|
|
|
|
|
return this->elements;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-01 18:43:22 +00:00
|
|
|
|
constexpr iterator Begin()
|
|
|
|
|
{
|
|
|
|
|
return this->elements;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr const_iterator Begin() const
|
|
|
|
|
{
|
|
|
|
|
return this->elements;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-18 10:49:32 +00:00
|
|
|
|
constexpr iterator end()
|
|
|
|
|
{
|
|
|
|
|
return this->elements + kElementCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr const_iterator end() const
|
|
|
|
|
{
|
|
|
|
|
return this->elements + kElementCount;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-01 18:43:22 +00:00
|
|
|
|
constexpr iterator End()
|
|
|
|
|
{
|
|
|
|
|
return this->elements + kElementCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr const_iterator End() const
|
|
|
|
|
{
|
|
|
|
|
return this->elements + kElementCount;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-18 10:49:32 +00:00
|
|
|
|
constexpr const_iterator cbegin() const
|
|
|
|
|
{
|
|
|
|
|
return begin();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr const_iterator cend() const
|
|
|
|
|
{
|
|
|
|
|
return end();
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-01 18:43:22 +00:00
|
|
|
|
constexpr const_iterator CBegin() const
|
|
|
|
|
{
|
|
|
|
|
return begin();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr const_iterator CEnd() const
|
|
|
|
|
{
|
|
|
|
|
return end();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr const_reverse_iterator rbegin() const
|
|
|
|
|
{
|
|
|
|
|
return reverse_iterator(end());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr reverse_iterator RBegin()
|
|
|
|
|
{
|
|
|
|
|
return reverse_iterator(end());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr const_reverse_iterator RBegin() const
|
|
|
|
|
{
|
|
|
|
|
return const_reverse_iterator(end());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr reverse_iterator rend()
|
|
|
|
|
{
|
|
|
|
|
return reverse_iterator(begin());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr const_reverse_iterator rend() const
|
|
|
|
|
{
|
|
|
|
|
return reverse_iterator(begin());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr reverse_iterator REnd()
|
|
|
|
|
{
|
|
|
|
|
return const_reverse_iterator(begin());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr const_reverse_iterator REnd() const
|
|
|
|
|
{
|
|
|
|
|
return const_reverse_iterator(begin());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr const_reverse_iterator crbegin() const
|
|
|
|
|
{
|
|
|
|
|
return const_reverse_iterator(end());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr const_reverse_iterator crend() const
|
|
|
|
|
{
|
|
|
|
|
return const_reverse_iterator(begin());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr const_reverse_iterator CRBegin() const
|
|
|
|
|
{
|
|
|
|
|
return const_reverse_iterator(end());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr const_reverse_iterator CREnd() const
|
|
|
|
|
{
|
|
|
|
|
return const_reverse_iterator(begin());
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-18 10:49:32 +00:00
|
|
|
|
constexpr size_type size() const
|
|
|
|
|
{
|
|
|
|
|
return kElementCount;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-01 18:43:22 +00:00
|
|
|
|
constexpr size_type Size() const
|
|
|
|
|
{
|
|
|
|
|
return kElementCount;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-18 10:49:32 +00:00
|
|
|
|
constexpr size_type max_size() const
|
|
|
|
|
{
|
|
|
|
|
return kElementCount;
|
|
|
|
|
}
|
2022-04-01 04:06:53 +00:00
|
|
|
|
|
2024-09-01 18:43:22 +00:00
|
|
|
|
constexpr size_type MaxSize() const
|
|
|
|
|
{
|
|
|
|
|
return kElementCount;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-18 10:49:32 +00:00
|
|
|
|
constexpr bool empty() const
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-01 18:43:22 +00:00
|
|
|
|
constexpr bool Empty() const
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-18 10:49:32 +00:00
|
|
|
|
reference at(size_type pos)
|
|
|
|
|
{
|
|
|
|
|
#if defined(AU_CFG_ID_DEBUG)
|
|
|
|
|
if (pos >= kElementCount)
|
|
|
|
|
{
|
|
|
|
|
AuMemoryPanic("out of bounds access");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return this->elements[pos];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr const_reference at(size_type pos) const
|
|
|
|
|
{
|
|
|
|
|
#if defined(AU_CFG_ID_DEBUG)
|
|
|
|
|
if (pos >= kElementCount)
|
|
|
|
|
{
|
|
|
|
|
AuMemoryPanic("out of bounds access");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
return this->elements[pos];
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-01 18:43:22 +00:00
|
|
|
|
reference At(size_type pos)
|
|
|
|
|
{
|
|
|
|
|
#if defined(AU_CFG_ID_DEBUG)
|
|
|
|
|
if (pos >= kElementCount)
|
|
|
|
|
{
|
|
|
|
|
AuMemoryPanic("out of bounds access");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return this->elements[pos];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr const_reference At(size_type pos) const
|
|
|
|
|
{
|
|
|
|
|
#if defined(AU_CFG_ID_DEBUG)
|
|
|
|
|
if (pos >= kElementCount)
|
|
|
|
|
{
|
|
|
|
|
AuMemoryPanic("out of bounds access");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
return this->elements[pos];
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-18 10:49:32 +00:00
|
|
|
|
reference operator[](size_type pos)
|
|
|
|
|
{
|
|
|
|
|
#if defined(AU_CFG_ID_DEBUG)
|
|
|
|
|
if (pos >= kElementCount)
|
|
|
|
|
{
|
|
|
|
|
AuMemoryPanic("out of bounds access");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return this->elements[pos];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr const_reference operator[](size_type pos) const
|
|
|
|
|
{
|
|
|
|
|
#if defined(AU_CFG_ID_DEBUG)
|
|
|
|
|
if (pos >= Count)
|
|
|
|
|
{
|
|
|
|
|
AuMemoryPanic("out of bounds access");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return this->elements[pos];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr reference front()
|
|
|
|
|
{
|
|
|
|
|
return this->elements[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr const_reference front() const
|
|
|
|
|
{
|
|
|
|
|
return this->elements[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr reference back()
|
|
|
|
|
{
|
|
|
|
|
return this->elements[Count - 1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr const_reference back() const
|
|
|
|
|
{
|
|
|
|
|
return this->elements[Count - 1];
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-01 18:43:22 +00:00
|
|
|
|
constexpr reference Front()
|
|
|
|
|
{
|
|
|
|
|
return this->elements[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr const_reference Front() const
|
|
|
|
|
{
|
|
|
|
|
return this->elements[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr reference Back()
|
|
|
|
|
{
|
|
|
|
|
return this->elements[Count - 1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr const_reference Back() const
|
|
|
|
|
{
|
|
|
|
|
return this->elements[Count - 1];
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-18 10:49:32 +00:00
|
|
|
|
constexpr T *data()
|
|
|
|
|
{
|
|
|
|
|
return this->elements;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr const T *data() const
|
|
|
|
|
{
|
|
|
|
|
return this->elements;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-01 18:43:22 +00:00
|
|
|
|
constexpr T *Data()
|
|
|
|
|
{
|
|
|
|
|
return this->elements;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr const T *Data() const
|
|
|
|
|
{
|
|
|
|
|
return this->elements;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-18 10:49:32 +00:00
|
|
|
|
// oh look, its that feature in that nearly 30 year old programming language intended to replace xerox alto's OOP language for the internet era.
|
|
|
|
|
AuUInt HashCode() const
|
|
|
|
|
{
|
|
|
|
|
AuUInt uRet {};
|
|
|
|
|
|
2024-09-01 18:43:22 +00:00
|
|
|
|
if constexpr (AuIsTriviallyCopyable_v<T>)
|
2023-01-18 10:49:32 +00:00
|
|
|
|
{
|
|
|
|
|
return AuFnv1aRuntime(this->elements, sizeof(this->elements));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (AU_ITERATE_N(i, kElementCount))
|
|
|
|
|
{
|
|
|
|
|
uRet ^= AuHashCode(this->elements[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return uRet;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
#if !defined(AURORA_RUNTIME_AU_ARRAY)
|
|
|
|
|
#define AURORA_RUNTIME_AU_ARRAY std::array
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
template <class T, size_t Z>
|
|
|
|
|
using AuArray = AURORA_RUNTIME_AU_ARRAY<T, Z>;
|
2023-01-18 16:29:35 +00:00
|
|
|
|
#endif
|