CXXIter 0.2
Loading...
Searching...
No Matches
Common.h
1#pragma once
2
3#include <limits>
4#include <optional>
5#include <algorithm>
6#include <type_traits>
7
8#include "IterValue.h"
9#include "SizeHint.h"
10#include "Traits.h"
11#include "util/Constraints.h"
12
13namespace CXXIter {
14
15 // ################################################################################################
16 // PUBLIC STRUCTURES AND DEFINITIONS
17 // ################################################################################################
18
22 enum class SortOrder {
23 ASCENDING,
24 DESCENDING
25 };
27 static constexpr SortOrder ASCENDING = SortOrder::ASCENDING;
29 static constexpr SortOrder DESCENDING = SortOrder::DESCENDING;
30
38 N,
43 };
44
45
46
47 // ################################################################################################
48 // INTERNALS
49 // ################################################################################################
50
52 namespace {
53 #define CXXITER_CHAINER_NODISCARD_WARNING "The result of chainer methods needs to be used, otherwise the iterator will not be doing any work."
54
55 template<size_t START, size_t END, typename F>
56 constexpr bool constexpr_for(F&& f) {
57 if constexpr (START < END) {
58 if(f(std::integral_constant<size_t, START>()) == false) { return false; }
59 if(constexpr_for<START + 1, END>(f) == false) { return false; }
60 }
61 return true;
62 }
63
64 template<typename TConstSrc, typename TOut>
65 using copy_const_from = std::conditional_t<
66 std::is_const_v<std::remove_reference_t<TConstSrc>>,
67 std::add_const_t<TOut>,
68 std::remove_const_t<TOut>
69 >;
70 }
71
72 template<typename T>
73 concept CXXIterIterator =
74 (std::is_same_v<typename trait::Iterator<T>::Self, T>) &&
75 requires(typename trait::Iterator<T>::Self& self, const typename trait::Iterator<T>::Self& constSelf, size_t n) {
78 {trait::Iterator<T>::next(self)} -> std::same_as<IterValue<typename trait::Iterator<T>::Item>>;
79 {trait::Iterator<T>::sizeHint(constSelf)} -> std::same_as<SizeHint>;
80 {trait::Iterator<T>::advanceBy(self, n)} -> std::same_as<size_t>;
81 };
82
83 template<typename T>
84 concept CXXIterDoubleEndedIterator = CXXIterIterator<T> && requires(typename trait::Iterator<T>::Self& self) {
85 {trait::DoubleEndedIterator<T>::nextBack(self)} -> std::same_as<IterValue<typename trait::Iterator<T>::Item>>;
86 };
87
88 template<typename T>
89 concept CXXIterExactSizeIterator = CXXIterIterator<T> && requires(const typename trait::Iterator<T>::Self& self) {
90 {trait::ExactSizeIterator<T>::size(self)} -> std::same_as<size_t>;
91 };
92
93 template<typename T>
94 concept CXXIterContiguousMemoryIterator = CXXIterExactSizeIterator<T>
95 && requires(typename trait::Iterator<T>::Self& self) {
97 {trait::ContiguousMemoryIterator<T>::currentPtr(self)} -> std::same_as<typename trait::ContiguousMemoryIterator<T>::ItemPtr>;
98 };
99
100 template<CXXIterIterator TSelf> class IterApi;
101
102}
CXXIter.
Definition: CXXIter.h:48
SortOrder
SortOrder for the item sorting methods.
Definition: Common.h:22
StatisticNormalization
Normalization variant to use while calculating statistics (mean / stddev / ...)
Definition: Common.h:34
@ N
Use when the mean, variance, stddev is calculated with the COMPLETE population.
@ N_MINUS_ONE
Use when the mean, variance, stddev is calculated from a sample of the population.
static constexpr ItemPtr currentPtr(typename trait::Iterator< T >::Self &self)=delete
Get the pointer of the current element.
std::add_pointer_t< std::remove_reference_t< typename Iterator< T >::Item > > ItemPtr
Pointer type to an item of this iterator.
Definition: Traits.h:83
static constexpr IterValue< typename Iterator< T >::Item > nextBack(Self &self)=delete
Pull the next last element from the iterator pipeline previous to this pipeline-element.
static constexpr size_t size(const typename trait::Iterator< T >::Self &self)=delete
Get the iterator's exact number of elements.
static constexpr IterValue< Item > next(Self &self)=delete
Pull one element from the iterator pipeline previous to this pipeline-element.
void Item
Item-Type. This is the type of elements that can be pulled from this pipeline-element.
Definition: Traits.h:32
trait::Iterator< T > Self
Self-Type. This is the type of the struct for which the trait::Iterator is being specialized.
Definition: Traits.h:28
static constexpr SizeHint sizeHint(const Self &self)=delete
Get the bounds on the remaining length of the iterator pipeline until this pipeline-element,...
static constexpr size_t advanceBy(Self &self, size_t n)=delete
Advance the iterator by n elements.