tcbrindle / flux

A C++20 library for sequence-orientated programming
https://tristanbrindle.com/flux/
Boost Software License 1.0
476 stars 29 forks source link

Add flux::repeat #74

Closed tcbrindle closed 1 year ago

tcbrindle commented 1 year ago

This has two overloads:

The first works like single(obj).cycle(), and the second works like single(obj).cycle(n). Or repeat(obj).take(n). Or single(obj).cycle().take(n)...

Both overloads are always random-access, and the finite version is additionally sized and bounded.

Like cycle(), the infinite version of repeat() can theoretically rollover the size_t counter for very long-running processes (very very very long-running on 64-bit systems). This won't cause UB, but distance() might give incorrect results, or raise a runtime error if the counter exceeds the maximum representable value of a distance_t

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.04 :tada:

Comparison is base (51cda50) 97.79% compared to head (b822393) 97.83%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #74 +/- ## ========================================== + Coverage 97.79% 97.83% +0.04% ========================================== Files 63 64 +1 Lines 2132 2174 +42 ========================================== + Hits 2085 2127 +42 Misses 47 47 ``` | [Impacted Files](https://app.codecov.io/gh/tcbrindle/flux/pull/74?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tristan+Brindle) | Coverage Δ | | |---|---|---| | [include/flux/op/cycle.hpp](https://app.codecov.io/gh/tcbrindle/flux/pull/74?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tristan+Brindle#diff-aW5jbHVkZS9mbHV4L29wL2N5Y2xlLmhwcA==) | `100.00% <100.00%> (ø)` | | | [include/flux/source/repeat.hpp](https://app.codecov.io/gh/tcbrindle/flux/pull/74?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tristan+Brindle#diff-aW5jbHVkZS9mbHV4L3NvdXJjZS9yZXBlYXQuaHBw) | `100.00% <100.00%> (ø)` | | ... and [1 file with indirect coverage changes](https://app.codecov.io/gh/tcbrindle/flux/pull/74/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tristan+Brindle)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.