diff --git a/src/include/ranges/mrange.cc.h b/src/include/ranges/mrange.cc.h index 5264383..333e533 100644 --- a/src/include/ranges/mrange.cc.h +++ b/src/include/ranges/mrange.cc.h @@ -434,6 +434,50 @@ namespace CNORXZ return mIPack; } + template + template + constexpr decltype(auto) GMIndex::zip(const Index& ind, const F& f, const G& g) const + { + static_assert(is_index::value, "got non-index type"); + if constexpr(has_static_sub::value){ + static_assert(index_dim::value == NI, + "got static-dimensional index with wrong dimension"); + if constexpr(std::is_same::value or std::is_same::value){ + iter<0,NI>( [&](auto i) { return std::get(mIPack)->zip(*std::get(ind.pack()), f); }, + NoF {} ); + f(*this, ind); + return; + } + else { + return iter<0,NI>( [&](auto i) { return std::get(mIPack)->zip(*std::get(ind.pack()), f); }, + [](auto... e) { return g(std::make_tuple(e...), f(*this, ind)); } ); + } + } + else if constexpr(has_sub::value){ + CXZ_ASSERT(ind.dim() == NI, "got index with wrong dimension = " << ind.dim() + << ", expected: " << NI); + if constexpr(std::is_same::value or std::is_same::value){ + iter<0,NI>( [&](auto i) { return std::get(mIPack)->zip(*ind.pack()[i],f); }, + NoF {} ); + f(*this, ind); + return; + } + else { + return iter<0,NI>( [&](auto i) { return std::get(mIPack)->zip(*ind.pack()[i],f); }, + [](auto... e) { return g(std::make_tuple(e...), f(*this, ind)); } ); + } + } + else { + if constexpr(std::is_same::value){ + f(*this, ind); + return; + } + else { + return f(*this, ind); + } + } + } + template const auto& GMIndex::blockSizes() const { diff --git a/src/include/ranges/mrange.h b/src/include/ranges/mrange.h index 3a9db8b..b89f5e9 100644 --- a/src/include/ranges/mrange.h +++ b/src/include/ranges/mrange.h @@ -70,6 +70,9 @@ namespace CNORXZ GMIndex& operator()(const Sptr>& mi); GMIndex& operator()(); + template + constexpr decltype(auto) zip(const Index& ind, const F& f, const G& g) const; // also non-const version !!! + const IndexPack& pack() const; const auto& blockSizes() const; const auto& lexBlockSizes() const; diff --git a/src/include/ranges/yrange.h b/src/include/ranges/yrange.h index 0abe012..a9b96da 100644 --- a/src/include/ranges/yrange.h +++ b/src/include/ranges/yrange.h @@ -56,7 +56,7 @@ namespace CNORXZ YIndex& operator()(const Sptr& i); YIndex& operator()(); - + const Vector& pack() const; const Vector& blockSizes() const; const Vector& lexBlockSizes() const;