|
@@ -0,0 +1,46 @@
|
|
|
+#ifndef SIMPLE_SUPPORT_ALGORITHM_COPY_HPP
|
|
|
+#define SIMPLE_SUPPORT_ALGORITHM_COPY_HPP
|
|
|
+
|
|
|
+#include <utility> // std::pair std::move
|
|
|
+
|
|
|
+#include "traits.hpp" // is_range_v
|
|
|
+#include "adl_helper.hpp" // adl_helper::adl_begin adl_helper::adl_end
|
|
|
+#include "reaches.hpp" // reaches
|
|
|
+
|
|
|
+namespace simple::support
|
|
|
+{
|
|
|
+
|
|
|
+ // you can duplicate a pattern from a beginning of a range via a single copy
|
|
|
+ // copy_n(pattern_begin, num_copies * pattern_size, pattern_end)
|
|
|
+ // this comes up in lz77 decompression
|
|
|
+ // unfortunately std is too clever for that (order not guaranteed)
|
|
|
+ // threw in 'reaches' abstraction as well
|
|
|
+
|
|
|
+ template <typename I, typename E, typename O>
|
|
|
+ constexpr std::pair<I,O> copy(I i, E i_end, O o)
|
|
|
+ {
|
|
|
+ for(; not reaches(i, i_end); ++i, ++o)
|
|
|
+ *o = *i;
|
|
|
+ return {std::move(i), std::move(o)};
|
|
|
+ }
|
|
|
+
|
|
|
+ template <typename I, typename O>
|
|
|
+ constexpr std::pair<I,O> copy_n(I i, std::size_t n, O o)
|
|
|
+ {
|
|
|
+ for(; n --> 0; ++i, ++o)
|
|
|
+ *o = *i;
|
|
|
+ return {std::move(i), std::move(o)};
|
|
|
+ }
|
|
|
+
|
|
|
+ // TODO: conflicts with copy in range_wrappers.hpp
|
|
|
+ // similar situation with find.hpp, but too lazy to update use cases rn
|
|
|
+ // template <typename Range, typename OutIt,
|
|
|
+ // std::enable_if_t<is_range_v<Range>>* = nullptr>
|
|
|
+ // constexpr auto copy(const Range& range, OutIt out)
|
|
|
+ // {
|
|
|
+ // return support::copy(adl_helper::adl_begin(range), adl_helper::adl_end(range), out);
|
|
|
+ // }
|
|
|
+
|
|
|
+} // namespace simple::support
|
|
|
+
|
|
|
+#endif /* end of include guard */
|