From f3c3a3bc4a1ef9826da789988ec735f3d5e2d790 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Thu, 8 Feb 2024 12:59:15 -0500 Subject: [PATCH] iterator offsetting --- include/blt/std/ranges.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/include/blt/std/ranges.h b/include/blt/std/ranges.h index bb29df4..0b70793 100644 --- a/include/blt/std/ranges.h +++ b/include/blt/std/ranges.h @@ -165,6 +165,41 @@ namespace blt return range_itr(_end - offset, offset == 0); } }; + + template + class itr_offset + { + private: + I begin_; + I end_; + public: + template + itr_offset(I begin, I end, T offset): begin_(begin), end_(end) + { + for (T t = 0; t < offset; t++) + ++begin_; + } + + template + itr_offset(C& container, T offset): begin_(container.begin()), end_(container.end()) + { + for (T t = 0; t < offset; t++) + ++begin_; + } + + auto begin() + { + return begin_; + } + + auto end() + { + return end_; + } + }; + + template + itr_offset(C, T) -> itr_offset; } #endif //BLT_RANGES_H