GCC Code Coverage Report


Directory: ./
File: include/CXXIter/src/Common.h
Date: 2023-01-04 16:32:12
Exec Total Coverage
Lines: 4 4 100.0%
Functions: 0 0 -%
Branches: 0 0 -%

Line Branch Exec Source
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
13 namespace CXXIter {
14
15 // ################################################################################################
16 // PUBLIC STRUCTURES AND DEFINITIONS
17 // ################################################################################################
18
19 /**
20 * @brief SortOrder for the item sorting methods.
21 */
22 enum class SortOrder {
23 ASCENDING,
24 DESCENDING
25 };
26 /** Shortcut for SortOrder::ASCENDING in the CXXIter namespace */
27 static constexpr SortOrder ASCENDING = SortOrder::ASCENDING;
28 /** Shortcut for SortOrder::DESCENDING in the CXXIter namespace */
29 static constexpr SortOrder DESCENDING = SortOrder::DESCENDING;
30
31 /**
32 * @brief Normalization variant to use while calculating statistics (mean / stddev / ...)
33 */
34 enum class StatisticNormalization {
35 /**
36 * @brief Use when the mean, variance, stddev is calculated with the COMPLETE population
37 */
38 N,
39 /**
40 * @brief Use when the mean, variance, stddev is calculated from a sample of the population
41 */
42 N_MINUS_ONE
43 };
44
45
46
47 // ################################################################################################
48 // INTERNALS
49 // ################################################################################################
50
51 /** @private */
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 180 constexpr bool constexpr_for(F&& f) {
57 if constexpr (START < END) {
58 132 if(f(std::integral_constant<size_t, START>()) == false) { return false; }
59 132 if(constexpr_for<START + 1, END>(f) == false) { return false; }
60 }
61 180 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) {
76 typename trait::Iterator<T>::Self;
77 typename trait::Iterator<T>::Item;
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) {
96 typename trait::ContiguousMemoryIterator<T>::ItemPtr;
97 {trait::ContiguousMemoryIterator<T>::currentPtr(self)} -> std::same_as<typename trait::ContiguousMemoryIterator<T>::ItemPtr>;
98 };
99
100 template<CXXIterIterator TSelf> class IterApi;
101
102 }
103