diff options
| author | Claudius "keldu" Holeksa <mail@keldu.de> | 2025-10-29 18:24:21 +0100 |
|---|---|---|
| committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2025-10-29 18:24:21 +0100 |
| commit | f8f210993fe199c40df63827c8b1ae0257b02753 (patch) | |
| tree | 93b0c81ea5288962216361f36d03415807396f37 /lib/c++/iterator.hpp | |
| parent | ff5785145d08b6a8fc5ab07caab441ed5ccfb2dd (diff) | |
| download | libs-lbm-master.tar.gz | |
Diffstat (limited to 'lib/c++/iterator.hpp')
| -rw-r--r-- | lib/c++/iterator.hpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/c++/iterator.hpp b/lib/c++/iterator.hpp index 78babff..866543a 100644 --- a/lib/c++/iterator.hpp +++ b/lib/c++/iterator.hpp @@ -14,6 +14,42 @@ void iterate_over(Func&& func, const saw::data<sch::FixedArray<sch::UInt64,2u>>& } return; } + +/** + * + */ +template<uint64_t D> +struct iterator { +private: + template<uint64_t i, typename Func> + static void iterate_over_i(Func& func, + const saw::data<sch::FixedArray<sch::UInt64,D>>& start, + const saw::data<sch::FixedArray<sch::UInt64,D>>& end, + const saw::data<sch::FixedArray<sch::UInt64,D>>& dist, + saw::data<sch::FixedArray<sch::UInt64,D>>& iter + ){ + static_assert(i <= D, "Eh. Too tired to think of a good message"); + if constexpr ( i == D ){ + func(iter); + }else{ + for(iter.at({i}) = start.at({i})+dist.at({i}); (iter.at({i})+dist.at({i}) < end.at({i})); ++iter.at({i})){ + iterate_over_i<i+1u,Func>(func,start,end,dist,iter); + } + } + } +public: + template<typename Func> + static void apply( + Func&& func, + const saw::data<sch::FixedArray<sch::UInt64,D>>& start, + const saw::data<sch::FixedArray<sch::UInt64,D>>& end, + const saw::data<sch::FixedArray<sch::UInt64,D>>& dist = {} + ){ + saw::data<sch::FixedArray<sch::UInt64,D>> iter; + iterate_over_i<0u,Func>(func, start, end, dist, iter); + } +}; + /* Ambiguous template<typename Func> void iterate_over(Func&& func, const saw::data<sch::FixedArray<sch::UInt64,3u>>& start, const saw::data<sch::FixedArray<sch::UInt64,3u>>& end, const saw::data<sch::FixedArray<sch::UInt64,3u>>& dist = {{{0u,0u,0u}}}){ |
