5 #ifndef HERALD_RANGES_H
6 #define HERALD_RANGES_H
20 #include <type_traits>
23 #include "../datatype/date.h"
34 template <
typename ValT>
36 return s.taken > from;
46 template <
typename Pred1,
typename Pred2>
48 dual_filter(
const Pred1 p1,
const Pred2 p2) : pred1(p1), pred2(p2) {}
51 template <
typename VTOther>
52 bool operator()(
const VTOther& value)
const {
53 return pred1(value) && pred2(value);
62 template <
typename VT>
64 in_range(
const VT min,
const VT max) : min(min), max(max) {}
67 template <
typename VTOther>
68 bool operator()(
const VTOther& value)
const {
69 return value >= min && value <= max;
77 template <
typename VT>
82 template <
typename VTOther>
83 bool operator()(
const VTOther& value)
const {
91 template <
typename VT>
96 template <
typename VTOther>
97 bool operator()(
const VTOther& value)
const {
115 template <
typename Coll,
117 typename ValT =
typename std::remove_cv<typename Coll::value_type>::type,
118 typename IterT =
typename Coll::iterator,
119 typename SizeT =
typename Coll::size_type
122 using base_iterator = IterT;
123 using base_value_type = ValT;
124 using base_size_type = SizeT;
126 iterator_proxy(Coll& coll) : coll(coll), iter(std::move(std::begin(coll))), endIter(std::move(std::end(coll))) {}
131 auto operator*() ->
const ValT& {
148 bool operator==(IterT otherIter)
const {
149 return iter == otherIter;
152 bool operator!=(IterT otherIter)
const {
153 return iter != otherIter;
156 friend bool operator!=(IterT otherIter,iterator_proxy<Coll> thisIter) {
157 return otherIter != thisIter.iter;
160 friend bool operator==(IterT otherIter,iterator_proxy<Coll> thisIter) {
161 return otherIter == thisIter.iter;
173 return endIter == iter;
176 Coll& collection()
const {
191 template <
typename Pred>
193 filter_fn(
const Pred pred) : pred(pred) {}
196 template <
typename ValT>
197 auto operator()(
const ValT& val) ->
bool {
201 const Pred predicate()
const {
211 template <
typename IterProxyT,
212 typename BaseValT =
typename IterProxyT::base_value_type,
213 typename BaseIterT =
typename IterProxyT::base_iterator,
214 typename BaseSizeT =
typename IterProxyT::base_size_type>
217 using value_type = BaseValT;
218 using iterator = BaseIterT;
219 using size_type = BaseSizeT;
221 using is_proxy = std::true_type;
223 view(IterProxyT srcIter) : source(std::forward<IterProxyT>(srcIter)) {}
226 auto begin() -> IterProxyT {
230 auto end() -> BaseIterT {
239 return (*(source.end() - 1)).taken;
242 template <
typename IterT>
243 bool operator==(
const IterT& other) {
244 return other == source;
247 template <
typename IterT>
248 bool operator!=(
const IterT& other) {
249 return other != source;
252 auto size() -> BaseSizeT {
256 auto end = source.end();
257 while (iter != end) {
266 auto operator[](BaseSizeT position) -> BaseValT {
267 return *(source + position);
282 template <
typename Coll,
285 typename ValT =
typename std::remove_cv<typename Coll::value_type>::type,
286 typename IterT =
typename Coll::iterator,
287 typename SizeT =
typename Coll::size_type
290 using base_iterator = IterT;
291 using base_coll_type = Coll;
292 using base_pred_type = Pred;
293 using base_value_type = ValT;
294 using base_size_type = SizeT;
296 using value_type = ValT;
297 using iterator = IterT;
298 using size_type = SizeT;
301 using is_proxy = std::true_type;
303 filtered_iterator_proxy(Coll& coll, Pred pred) : coll(coll), iter(std::move(std::begin(coll))), endIter(std::move(std::end(coll))),
filter(pred) {
314 auto operator*() ->
const ValT& {
332 filtered_iterator_proxy<Coll,Pred> operator+(
int by) {
333 filtered_iterator_proxy<Coll,Pred> cp = *
this;
334 for (
int i = 0;i < by;++i) {
340 bool operator==(IterT otherIter)
const {
341 return iter == otherIter;
344 bool operator!=(IterT otherIter)
const {
345 return iter != otherIter;
348 friend bool operator!=(IterT otherIter,filtered_iterator_proxy<Coll,Pred> thisIter) {
349 return otherIter != thisIter.iter;
352 friend bool operator==(IterT otherIter,filtered_iterator_proxy<Coll,Pred> thisIter) {
353 return otherIter == thisIter.iter;
365 return endIter == iter;
368 Coll& collection()
const {
372 Pred predicate()
const {
373 return filter.predicate();
380 filter_fn<Pred> filter;
384 while (endIter != iter && !filter(*iter)) {
390 if (endIter == iter)
return;
393 }
while (endIter != iter && !filter(*iter));
403 template <
typename Pred>
406 filter(
const Pred& pred) : pred(pred) {}
409 template <
typename Coll>
414 template <
typename OtherColl,
typename OtherPred>
419 template <
typename Coll>
435 template <
typename IterProxyT>
449 template <
typename SampleT,
450 std::size_t ListSize,
Acts as a non-global memory arena for arbitrary classes.
Definition: aggregates.h:15
The Sample taken from an object with ID of type SampledID.
Definition: sampling.h:28
Definition: sampling.h:102
dual or chained filter
Definition: ranges.h:47
filtered_iterator_proxy< Coll, Pred > & operator++()
prefix operator
Definition: ranges.h:319
iterator_proxy< Coll > & operator++()
prefix operator
Definition: ranges.h:136
friend auto operator|(herald::analysis::sampling::SampleList< SampleT, ListSize > &coll, to_view view) -> herald::analysis::views::view< IterProxyT >
Convert an unfiltered source collection into a view.
Definition: ranges.h:453