46 template<
typename...
ArgsA,
typename...
ArgsB>
bool operator()(
const std::tuple<ArgsA...>& a,
const std::tuple<ArgsB...>& b)
const {
47 static_assert(
sizeof...(ArgsA) ==
sizeof...(
ArgsB),
"comparing invalid tuples");
48 return std::get<
sizeof...(ArgsA) - 1>(a) == std::get<
sizeof...(ArgsB) - 1>(b);
53 template<
class A,
class B>
bool operator()(
const A&,
const B&)
const {
return false; }
78 template<
typename... Args>
void dummy(Args&&...) {}
80 template<
typename... Args>
void operator()(std::tuple<Args...>&
v) {
updateValues(
v, std::make_index_sequence<
sizeof...(Args)>()); }
84 using R =
decltype((std::declval<T&>().*
Method)());
120 template<
typename T>
decltype(
auto)
operator()(
T&
v)
const {
return callback(*
v); }
125 if constexpr(std::is_reference<decltype(*std::get<Idx>(
v))>::value) {
126 return std::reference_wrapper(*std::get<Idx>(
v));
128 return *std::get<Idx>(
v);
136 template<
typename... Args>
auto operator()(std::tuple<Args...>&
v)
const {
142 using R =
decltype((std::declval<T&>().*
Method)());
165 template<
class T,
typename D = impl::dereference::ByValueReference,
typename C = impl::compare::ByValue>
class IteratorPrototype {
169 using reference =
decltype(std::declval<D>()(std::declval<T&>()));
206 template<
class F,
class T>
static constexpr bool needsState = !std::is_same<void, decltype(std::declval<F>()(std::declval<T&>()))>::value;
211 template<
class T,
typename F = impl::increment::ByValue<1>,
typename D = impl::dereference::ByValueReference,
typename C = impl::compare::ByValue>
218 template<
typename TF = F,
typename TD = D,
typename TC = C>
224 if constexpr(Iterator::hasState) {
225 if(Iterator::state) {
235 if constexpr(Iterator::hasState) {
236 if(!Iterator::state) {
246 if constexpr(Iterator::hasState) {
253 explicit operator bool()
const {
254 if constexpr(Iterator::hasState) {
255 return Iterator::state;
267 template<
class T,
typename F = impl::increment::ByValue<1>,
typename D = impl::dereference::ByValueReference,
typename C = impl::compare::ByValue>
296 template<
class IB,
class IE,
class Context>
auto wrap(
IB&& a,
IE&& b,
Context&& context) {
303 return wrap(std::forward<IB>(
pair.first), std::forward<IE>(
pair.second), std::forward<Context>(context));
331 template<
class T>
auto range(
T begin,
T end,
T increment) {
332 if constexpr(std::is_floating_point_v<T>) {
335 const T actualEnd = end - ((end - begin) % increment);
350 template<
class T = UInt64>
auto range() {
return range<T>(std::numeric_limits<T>::max()); }
354 template<
typename T = UInt64,
typename Container>
auto indices(
const Container& container) {
return range<T>(
T(0),
T(container.size())); }
358 template<
typename Container>
auto indices(
const Container& container) {
359 using T =
decltype(container.size());
369 template<
typename... Args>
auto zip(Args&&... args) {
374 return wrap(std::move(begin), std::move(end));
380 template<
typename Container>
auto keys(Container& container) {
381 using PairType = std::decay_t<
decltype(*container.begin())>;
389 template<
typename Container>
auto keys(Container&& container) {
390 using PairType = std::decay_t<
decltype(*container.begin())>;
400 template<
typename Container>
auto values(Container& container) {
401 using PairType = std::decay_t<
decltype(*container.begin())>;
409 template<
typename Container>
auto values(Container&& container) {
410 using PairType = std::decay_t<
decltype(*container.begin())>;
421 template<
typename Container>
auto dereference(Container& container) {
427 template<
typename Container>
auto dereference(Container&& container) {
452 auto begin = std::find_if(container.begin(), container.end(),
predicate);
453 const auto filter = [end = container.end(),
predicate = std::forward<Predicate>(
predicate)](
auto& iterator)
mutable {
454 iterator = std::find_if(++iterator, end,
predicate);
462 auto begin = std::find_if(container.begin(), container.end(),
predicate);
463 const auto filter = [end = container.end(),
predicate = std::forward<Predicate>(
predicate)](
auto& iterator)
mutable {
464 iterator = std::find_if(++iterator, end,
predicate);
473 template<
typename Container>
auto unique(Container& container) {
474 const auto callback = [end = container.end(), current = container.begin()](
auto& iterator)
mutable {
475 current = iterator = std::find_if_not(++iterator, end, [&](
auto&
candidate) {
486 template<
typename Container>
auto unique(Container&& container) {
487 const auto callback = [end = container.end(), current = container.begin()](
auto& iterator)
mutable {
488 current = iterator = std::find_if_not(++iterator, end, [&](
auto&
candidate) {
499 template<
typename Container>
auto skipNull(Container& container) {
500 return filter(container, [](
const auto&
v) {
return v !=
nullptr; });
504 template<
typename Container>
auto skipNull(Container&& container) {
505 return filter(std::forward<Container>(container), [](
const auto&
v) {
return v !=
nullptr; });
511 template<
typename Container>
auto weakLock(Container& container) {
512 return transform(container, [](
const auto& value) {
return value.lock(); });
516 template<
typename Container>
auto weakLock(Container&& container) {
517 return transform(std::forward<Container>(container), [](
const auto& value) {
return value.lock(); });
535 if constexpr(std::is_base_of<InitializedIterable, T>::value) {
538 return std::move(
start);
547 template<
class T,
class I = impl::increment::ByValue<1>>
auto valuesBetween(
T* begin,
T* end) {
552 template<
class T,
class A>
void fill(
A&
arr,
const T& value) {
564 template<
class A,
class B,
class T = impl::dereference::ByValueReference>
void copy(
const A& a,
B& b,
T&&
t =
T()) {
565 for(
auto [
v1,
v2] :
zip(a, b)) {
572 template<
class I,
class C>
decltype(&*std::declval<I>())
found(
const I& it,
C& container) {
573 if(it != container.end()) {
582 if(it != container.end()) {
598template<
class T,
typename F,
typename D,
typename C>
struct std::iterator_traits<
CeresEngine::
Iterator<T, F, D, C>> {
601 using difference_type =
typename Iterator::difference_type;
602 using value_type =
typename Iterator::value_type;
603 using pointer =
typename Iterator::pointer;
604 using reference =
typename Iterator::reference;
605 using iterator_category =
typename Iterator::iterator_category;
#define CE_FORCE_INLINE
Definition Macros.hpp:367
#define CE_ASSERT(...)
Definition Macros.hpp:323
IteratorPrototype where advance is defined by the functional held by F.
Definition Iterator.hpp:212
friend bool operator!=(const Iterator &lhs, const IterationEnd &rhs)
Definition Iterator.hpp:245
friend bool operator==(const Iterator &lhs, const IterationEnd &rhs)
Definition Iterator.hpp:243
Base::DereferencedType operator*() const
Definition Iterator.hpp:234
Iterator(T &&begin, F &&_callback=F(), D &&_dereferencer=D(), C &&_compare=C())
Definition Iterator.hpp:219
Iterator & operator++()
Definition Iterator.hpp:223
F callback
Definition Iterator.hpp:215
Base class for simple iterators.
Definition Iterator.hpp:165
decltype(std::declval< D >()(std::declval< T & >())) reference
Definition Iterator.hpp:169
auto * operator->() const
Definition Iterator.hpp:187
IteratorPrototype(T &&first, D &&_dereferencer=D(), C &&_compare=C())
Definition Iterator.hpp:183
decltype(dereferencer(value)) DereferencedType
Definition Iterator.hpp:180
value_type * pointer
Definition Iterator.hpp:171
C compare
Definition Iterator.hpp:176
IteratorPrototype()=delete
D dereferencer
Definition Iterator.hpp:175
T value
Definition Iterator.hpp:179
friend bool operator!=(const IteratorPrototype &lhs, const IteratorPrototype &rhs)
Definition Iterator.hpp:190
typename std::decay< reference >::type value_type
Definition Iterator.hpp:170
std::input_iterator_tag iterator_category
Definition Iterator.hpp:168
std::ptrdiff_t difference_type
Definition Iterator.hpp:172
friend bool operator==(const IteratorPrototype &lhs, const IteratorPrototype &rhs)
Definition Iterator.hpp:189
DereferencedType operator*()
Definition Iterator.hpp:186
Definition Application.hpp:19
bool eraseIfFound(const I &it, C &container)
Removes a value from a container with find method.
Definition Iterator.hpp:581
auto range()
Returns an iterator that increases it's value from 0 to end by 1 for each step.
Definition Iterator.hpp:350
Iterator< T, F, D, C > makeIterator(T &&t, F f=F(), D &&d=D(), C &&c=C())
Definition Iterator.hpp:268
auto indices(const Container &container)
Returns an iterator that increases it's value from 0 to container.size() by 1 on each step.
Definition Iterator.hpp:354
RangeIterator< T > rangeValue(T v, T i=1)
Definition Iterator.hpp:327
auto zip(Args &&... args)
Returns an iterable object where all argument iterators are traversed simultaneously.
Definition Iterator.hpp:369
auto valuesBetween(T *begin, T *end)
Iterates over the dereferenced values between begin and end.
Definition Iterator.hpp:547
@ Method
Indicates that the item is a method.
std::pair< First, Second > Pair
Pair is a struct template that provides a way to store two heterogeneous objects as a single unit.
Definition Pair.hpp:18
auto skipNull(Container &container)
Returns an iterable object that iterates over the non-null values of container.
Definition Iterator.hpp:499
auto move(Vector3 position)
Moves a entity to the given position.
Definition Helpers.hpp:22
auto values(Container &container)
Returns an iterable object that iterates over the values of a map-like container.
Definition Iterator.hpp:400
Iterator(const T &) -> Iterator< T >
auto weakLock(Container &container)
Returns an iterable object that iterates over the locked weak pointers of Container.
Definition Iterator.hpp:511
auto wrap(IB &&a, IE &&b, Context &&context)
Wraps two iterators into a single-use container with begin/end methods to match the C++ iterator conv...
Definition Iterator.hpp:296
auto keys(Container &container)
Returns an iterable object that iterates over the keys of a map-like container.
Definition Iterator.hpp:380
constexpr auto predicate(Callable &&callable) noexcept
Helper function to create a new predicate from a lambda.
Definition Predicate.hpp:390
auto unique(Container &container)
Returns an iterable object that iterates over all unique values on the container.
Definition Iterator.hpp:473
auto dereference(Container &container)
Returns an iterable object that iterates over the values of Container but also dereferences the point...
Definition Iterator.hpp:421
@ Transform
Indicates that the object transform is dirty.
void copy(const A &a, B &b, T &&t=T())
Copies values from one container to another.
Definition Iterator.hpp:564
auto transform(Container &container, Transform &&transform)
Returns an iterable object that iterates over the values of the container and applies transform to ev...
Definition Iterator.hpp:436
void fill(A &arr, const T &value)
Copy-assigns the given value to every element in a container.
Definition Iterator.hpp:552
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
auto reverse(T &v)
Wraps the rbegin and rend iterators.
Definition Iterator.hpp:364
decltype(&*std::declval< I >() found)(const I &it, C &container)
Returns a pointer to the value if found, otherwise nullptr.
Definition Iterator.hpp:572
auto filter(Container &container, Predicate &&predicate)
Returns an iterable object that iterates over the values of the container and applies transform to ev...
Definition Iterator.hpp:451
When used as a base class for a iterator type, MakeIterable will call the bool init() member before i...
Definition Iterator.hpp:523
The end state for self-contained iterators.
Definition Iterator.hpp:26
const IterationEnd & operator*() const
Definition Iterator.hpp:27
Take a class T with that defines the methods T::advance() and O T::value() for any type O and wraps i...
Definition Iterator.hpp:529
MakeIterable(Args &&... args)
Definition Iterator.hpp:543
MakeIterable(T &&value)
Definition Iterator.hpp:542
Iterator< T, impl::increment::ByMemberCall< T, decltype(&T::advance), &T::advance >, impl::dereference::ByMemberCall< T, decltype(&T::value), &T::value >, impl::compare::ByValue > start
Definition Iterator.hpp:532
auto && begin() const
Definition Iterator.hpp:534
auto end() const
Definition Iterator.hpp:540
A type that predicate types must extend to allow automatic operator overloading.
Definition Predicate.hpp:19
Helper class for range().
Definition Iterator.hpp:315
RangeIterator(const T &start, const T &_increment=1)
Definition Iterator.hpp:318
RangeIterator & operator++()
Definition Iterator.hpp:321
T increment
Definition Iterator.hpp:316
Exception when dereferencing an undefined iterator value.
Definition Iterator.hpp:154
const char * what() const noexcept override
Definition Iterator.hpp:155
IB && begin() const
Definition Iterator.hpp:289
IE && end() const
Definition Iterator.hpp:290
IE endIterator
Definition Iterator.hpp:288
IB beginIterator
Definition Iterator.hpp:287
WrappedIterator(IB &&begin, IE &&end)
Definition Iterator.hpp:291
Helper class for wrap().
Definition Iterator.hpp:276
IB && begin() const
Definition Iterator.hpp:280
Context mContext
Definition Iterator.hpp:277
IB beginIterator
Definition Iterator.hpp:278
IE endIterator
Definition Iterator.hpp:279
WrappedIterator(IB &&begin, IE &&end, Context &&context)
Definition Iterator.hpp:282
IE && end() const
Definition Iterator.hpp:281
Definition Iterator.hpp:198
static constexpr bool hasState
Definition Iterator.hpp:199
bool state
Definition Iterator.hpp:200
Definition Iterator.hpp:202
static constexpr bool hasState
Definition Iterator.hpp:203
Definition Iterator.hpp:41
bool operator()(const T &a, const T &b) const
Definition Iterator.hpp:42
Definition Iterator.hpp:45
bool operator()(const std::tuple< ArgsA... > &a, const std::tuple< ArgsB... > &b) const
Definition Iterator.hpp:46
Definition Iterator.hpp:37
bool operator()(const T &a, const T &b) const
Definition Iterator.hpp:38
Definition Iterator.hpp:33
bool operator()(const T &a, const T &b) const
Definition Iterator.hpp:34
Definition Iterator.hpp:52
bool operator()(const A &, const B &) const
Definition Iterator.hpp:53
Definition Iterator.hpp:117
ByCallback(Callback callback)
Definition Iterator.hpp:119
Callback callback
Definition Iterator.hpp:118
Definition Iterator.hpp:96
const T & operator()(T &v) const
Definition Iterator.hpp:97
Definition Iterator.hpp:141
decltype((std::declval< T & >().*Method)()) R
Definition Iterator.hpp:142
R operator()(T &v) const
Definition Iterator.hpp:143
Definition Iterator.hpp:146
auto & operator()(T &v) const
Definition Iterator.hpp:147
Dereferencing helper used to dereference a pointer type from a pointer iterator.
Definition Iterator.hpp:110
auto & operator()(T &v) const
Definition Iterator.hpp:111
Definition Iterator.hpp:123
auto constexpr getElement(T &v) const
Definition Iterator.hpp:124
auto operator()(std::tuple< Args... > &v) const
Definition Iterator.hpp:136
auto getReferenceTuple(T &v, std::index_sequence< Idx... >) const
Definition Iterator.hpp:132
Definition Iterator.hpp:104
Definition Iterator.hpp:92
T operator()(T &v) const
Definition Iterator.hpp:93
Definition Iterator.hpp:100
T & operator()(T &v) const
Definition Iterator.hpp:101
Definition Iterator.hpp:71
Callback callback
Definition Iterator.hpp:72
ByCallback(Callback callback)
Definition Iterator.hpp:73
void operator()(T &v) const
Definition Iterator.hpp:74
Definition Iterator.hpp:83
R operator()(T &v) const
Definition Iterator.hpp:85
decltype((std::declval< T & >().*Method)()) R
Definition Iterator.hpp:84
Definition Iterator.hpp:67
void operator()(T &v) const
Definition Iterator.hpp:68
Definition Iterator.hpp:63
void operator()(T &v) const
Definition Iterator.hpp:64
Definition Iterator.hpp:77
void operator()(std::tuple< Args... > &v)
Definition Iterator.hpp:80
void dummy(Args &&...)
Definition Iterator.hpp:78
void updateValues(T &v, std::index_sequence< Idx... >)
Definition Iterator.hpp:79
Definition Iterator.hpp:59
void operator()(T &v) const
Definition Iterator.hpp:60