18 template <
typename TIterator>
29 decltype(
auto) operator*()
const {
32 decltype(
auto) operator*() {
62 template <
typename TIterator>
70 template <
typename TContainer>
75 using Iterator = decltype(std::declval<std::decay_t<TContainer>>().
begin());
80 : container(
std::forward<T>(container)) {}
84 if (
Iterator iter = container.end()) {
94 if (
Iterator iter = container.begin()) {
103 return container.size();
114 template <
typename TContainer>
125 template <
typename TIterator>
131 using T = decltype((*std::declval<TIterator>())[std::declval<Size>()]);
132 using RawT = std::decay_t<T>;
145 , component(component) {}
148 return (*iterator)[component];
152 return (*iterator)[component];
189 return iterator - other.iterator;
192 return iterator < other.iterator;
195 return iterator > other.iterator;
198 return iterator <= other.iterator;
201 return iterator >= other.iterator;
204 return iterator == other.iterator;
207 return iterator != other.iterator;
213 template <
typename TBuffer>
240 template <
typename TBuffer>
252 template <
typename TElement,
typename... TIterator>
255 Tuple<TIterator...> iterators;
259 : iterators(iters...) {}
262 forEach(iterators, [](
auto& iter) { ++iter; });
267 return apply(iterators, [](
auto&... values) -> TElement {
return { *values... }; });
271 return apply(iterators, [](
const auto&... values) -> TElement {
return { *values... }; });
275 const bool result = iterators.template get<0>() == other.iterators.template get<0>();
277 SPH_ASSERT(checkEqual(result, other, std::index_sequence_for<TIterator...>{}));
282 const bool result = iterators.template get<0>() != other.iterators.template get<0>();
284 SPH_ASSERT(checkEqual(!result, other, std::index_sequence_for<TIterator...>{}));
289 template <std::size_t First, std::size_t... Rest>
290 bool checkEqual(
const bool equal,
const TupleIterator& other, std::index_sequence<First, Rest...>)
const {
291 if (equal != (iterators.template get<First>() == other.iterators.template get<First>())) {
295 return checkEqual(equal, other, std::index_sequence<Rest...>{});
299 bool checkEqual(
const bool,
const TupleIterator&, std::index_sequence<>)
const {
305 template <
typename TElement,
typename... TIterators>
312 template <
typename TElement,
typename... TContainers>
315 Tuple<TContainers...> tuple;
319 : tuple(
std::forward<TContainers>(containers)...) {
324 return apply(tuple, [](
auto&... containers) {
325 return makeTupleIterator<TElement>(containers.begin()...);
330 return apply(tuple, [](
const auto&... containers) {
331 return makeTupleIterator<TElement>(containers.begin()...);
336 return apply(tuple, [](
auto&... containers) {
337 return makeTupleIterator<TElement>(containers.end()...);
342 return apply(tuple, [](
const auto&... containers) {
343 return makeTupleIterator<TElement>(containers.end()...);
348 return tuple.template get<0>().
size();
352 template <
typename TElement,
typename... TContainers>
354 return TupleAdapter<TElement, TContainers...>(std::forward<TContainers>(containers)...);
361 template <
typename TValue>
393 template <
typename TValue>
399 template <
typename TIterator>
405 using TValue = decltype(*std::declval<TIterator>());
427 return iterator != other.iterator;
431 template <
typename TIterator>
437 template <
typename TContainer>
440 TContainer container;
444 : container(
std::forward<TContainer>(container)) {}
455 template <
typename TContainer>
464 template <
typename TIterator>
471 template <
typename TContainer>
474 first = container.begin() + firstIdx;
475 last = container.begin() + lastIdx;
487 template <
typename TContainer>
497 template <
typename TIterator,
typename TCondition>
502 TCondition condition;
505 SubsetIterator(
const TIterator& iterator,
const TIterator& end, TCondition&& condition)
508 , condition(
std::forward<TCondition>(condition)) {
510 while (iter != end && !condition(*iter)) {
518 }
while (iter != end && !condition(*iter));
527 INLINE decltype(
auto) operator*()
const {
533 return iter == other.iter;
537 return iter != other.iter;
542 template <
typename TIterator,
typename TCondition>
548 template <
typename TContainer,
typename TCondition>
551 TContainer container;
552 TCondition condition;
556 : container(
std::forward<TContainer>(container))
557 , condition(
std::forward<TCondition>(condition)) {}
569 template <
typename TContainer,
typename TCondition>
570 auto subset(TContainer&& container, TCondition&& condition) {
572 std::forward<TContainer>(container), std::forward<TCondition>(condition));
630 ofs << sequence.
from <<
" - " << sequence.
to;
#define SPH_ASSERT(x,...)
uint32_t Size
Integral type used to index arrays (by default).
ReverseAdapter< TContainer > reverse(TContainer &&container)
TupleAdapter< TElement, TContainers... > iterateTuple(TContainers &&... containers)
TupleIterator< TElement, TIterators... > makeTupleIterator(const TIterators &... iterators)
Creates TupleIterator from individual iterators, utilizing type deduction.
INLINE auto subrange(const TContainer &container, const Size firstIdx, const Size lastIdx)
IndexAdapter< TContainer > iterateWithIndex(TContainer &&container)
IteratorWithIndex< TIterator > makeIteratorWithIndex(TIterator &&iterator, const Size index)
INLINE auto makeSubsetIterator(const TIterator &iterator, const TIterator &end, TCondition &&condition)
ReverseIterator< TIterator > reverseIterator(const TIterator iter)
Creates reverse iterator by wrapping forward iterator, utilizes type deduction.
ElementWithIndex< TValue > makeElementWithIndex(TValue &&value, const Size index)
auto subset(TContainer &&container, TCondition &&condition)
auto componentAdapter(TBuffer &&buffer, const Size component)
Ordinary iterator for custom containers.
#define INLINE
Macros for conditional compilation based on selected compiler.
#define NAMESPACE_SPH_END
Re-implementation of std::tuple with some additional functionality.
decltype(auto) INLINE apply(Tuple< TArgs... > &tuple, TFunctor &&functor)
Expands arguments stored in tuple into parameter pack of a functor.
INLINE void forEach(Tuple< TArgs... > &tuple, TFunctor &&functor)
std::ptrdiff_t difference_type
Size operator-(const ComponentIterator &other) const
ComponentIterator(const TIterator &iterator, const int component)
ComponentIterator operator--(int)
typename TIterator::iterator_category iterator_category
bool operator>(const ComponentIterator &other) const
ComponentIterator operator++(int)
bool operator!=(const ComponentIterator &other)
bool operator<=(const ComponentIterator &other) const
void operator-=(const int n)
ComponentIterator operator+(const int n) const
ComponentIterator & operator++()
bool operator<(const ComponentIterator &other) const
bool operator>=(const ComponentIterator &other) const
const RawT & operator*() const
void operator+=(const int n)
ComponentIterator()=default
ComponentIterator & operator--()
bool operator==(const ComponentIterator &other)
ComponentIterator operator-(const int n) const
INLINE const TValue & value() const
INLINE Size index() const
ElementWithIndex(TValue &&value, const Size index)
IndexAdapter(TContainer &&container)
INLINE bool operator!=(const IndexIterator other) const
INLINE IndexIterator(const Size idx)
INLINE Size operator*() const
INLINE IndexIterator & operator++()
INLINE bool operator==(const IndexSequence &other) const
INLINE IndexIterator begin() const
INLINE IndexIterator end() const
INLINE IndexSequence(const Size from, const Size to)
friend std::ostream & operator<<(std::ostream &ofs, const IndexSequence &sequence)
Wrapper of iterator keeping also an index of current element.
ElementWithIndex< const TValue > operator*() const
IteratorWithIndex(const TIterator iterator, const Size index)
ElementWithIndex< TValue > operator*()
bool operator!=(const IteratorWithIndex &other) const
IteratorWithIndex & operator++()
Simple (forward) iterator over continuous array of objects of type T.
ReverseAdapter(T &&container)
ReverseIterator< Iterator > begin()
Returns iterator pointing to the last element in container.
ReverseIterator< Iterator > end()
Returns iterator pointiing to one before the first element.
Generic reverse iterator over continuous array of objects of type T.
bool operator!=(const ReverseIterator &other) const
ReverseIterator & operator--()
ReverseIterator(TIterator iter)
ReverseIterator operator--(int)
ReverseIterator operator++(int)
ReverseIterator()=default
bool operator==(const ReverseIterator &other) const
ReverseIterator & operator++()
Non-owning view to access and iterate over subset of container.
SubsetAdapter(TContainer &&container, TCondition &&condition)
Allows to iterate over a given subset of a container, given by condition functor.
SubsetIterator(const TIterator &iterator, const TIterator &end, TCondition &&condition)
INLINE SubsetIterator & operator++()
INLINE bool operator==(const SubsetIterator &other) const
INLINE bool operator!=(const SubsetIterator &other) const
TupleAdapter(TContainers &&... containers)
Holds multiple iterators, advancing all of them at the same time.
TupleIterator(const TIterator &... iters)
bool operator==(const TupleIterator &other) const
TupleIterator & operator++()
bool operator!=(const TupleIterator &other) const
const TElement operator*() const
Heterogeneous container capable of storing a fixed number of values.
static constexpr INLINE std::size_t size() noexcept
Returns the number of elements in tuple.
Overload of std::swap for Sph::Array.
Object with deleted copy constructor and copy operator.
INLINE TIterator begin() const
SubRange(const TContainer &container, const Size firstIdx, const Size lastIdx)
INLINE TIterator end() const
Wraps a vector container, providing means to iterate over given component of vector elements.
decltype(std::declval< TBuffer >().begin()) TIterator
VectorComponentAdapter(TBuffer &&data, const Size component)