[*] Improved RNG utils

This commit is contained in:
Reece Wilson 2024-01-17 17:46:31 +00:00
parent c3e0418e1a
commit 3e3a071e8e
2 changed files with 35 additions and 11 deletions

View File

@ -82,9 +82,12 @@ namespace Aurora::RNG
} }
template<typename T> template<typename T>
inline T &NextIterator(T &begin, T &end) inline T NextIterator(T begin, T end)
{ {
return begin + NextIndex(AuUInt(end - begin)); auto nextItr = begin;
auto uCount = std::distance(begin, end);
std::advance(nextItr, NextIndex(uCount));
return nextItr;
} }
template<typename T> template<typename T>
@ -92,17 +95,23 @@ namespace Aurora::RNG
{ {
return pItems[NextIndex(uCount)]; return pItems[NextIndex(uCount)];
} }
template<typename T> template<typename T>
inline T &NextVector(AuList<T> &items) inline auto NextRange(T &items)
{ {
return NextArray(items.data(), items.size()); return NextIterator(items.begin(), items.end());
} }
template<typename T> template<typename T>
inline T &NextRange(T &items) inline T &NextVector(AuList<T> &items)
{ {
return NextIterator(items.begin(), items.end()); return *NextRange(items);
}
template<typename T>
inline const T &NextVector(const AuList<T> &items)
{
return *NextRange(items);
} }
}; };

View File

@ -109,14 +109,29 @@ namespace Aurora::RNG
} }
template<typename T> template<typename T>
static auline T &RngVector(AuList<T> &items) inline T RngIterator(T begin, T end)
{ {
return RngArray(items.data(), items.size()); auto nextItr = begin;
auto uCount = std::distance(begin, end);
std::advance(nextItr, RngIndex(uCount));
return nextItr;
} }
template<typename T> template<typename T>
static auline T &RngRange(T &items) static auline auto RngRange(T &items)
{ {
return RngArray(items.begin(), items.end() - items.begin()); return RngIterator(std::begin(items), std::end(items));
}
template<typename T>
static auline T &RngVector(AuList<T> &items)
{
return *RngRange(items);
}
template<typename T>
static auline const T &RngVector(const AuList<T> &items)
{
return *RngRange(items);
} }
} }