diff --git a/src/ranges/container_range.h b/src/ranges/container_range.h index dc02f52..a2662c0 100644 --- a/src/ranges/container_range.h +++ b/src/ranges/container_range.h @@ -88,6 +88,10 @@ namespace MultiArrayTools std::string id(); void print(size_t offset); + template + auto ifor(Exprs&&... exs) const + -> decltype(RPackNum::mkFor(mIPack, exs...)); + }; @@ -366,6 +370,14 @@ namespace MultiArrayTools RPackNum::printIndex(mIPack, offset+1); } + template + template + auto ContainerIndex::ifor(Exprs&&... exs) const + -> decltype(RPackNum::mkFor(mIPack, exs...)) + { + return RPackNum::mkFor(mIPack, exs...); + } + /***************************** * ContainerRangeFactory * diff --git a/src/ranges/multi_range.h b/src/ranges/multi_range.h index f4b09d5..28735ce 100644 --- a/src/ranges/multi_range.h +++ b/src/ranges/multi_range.h @@ -103,6 +103,10 @@ namespace MultiArrayTools std::string id(); void print(size_t offset); + + template + auto ifor(Exprs&&... exs) const + -> decltype(RPackNum::mkFor(mIPack, exs...)); }; /************************* @@ -410,6 +414,13 @@ namespace MultiArrayTools RPackNum::printIndex(mIPack, offset+1); } + template + template + auto MultiIndex::ifor(Exprs&&... exs) const + -> decltype(RPackNum::mkFor(mIPack, exs...)) + { + return RPackNum::mkFor(mIPack, exs...); + } /************************* * MultiRangeFactory * diff --git a/src/ranges/rpack_num.h b/src/ranges/rpack_num.h index 590ae44..0bcdf17 100644 --- a/src/ranges/rpack_num.h +++ b/src/ranges/rpack_num.h @@ -219,6 +219,16 @@ namespace MultiArrayHelper RPackNum::buildInfoVec(out, ip, bs); } + template + static auto mkFor(const IndexPack& ipack, Exprs&&... exs) + -> decltype(std::get::value-N>(ipack) + ->ifor(RPackNum::template mkFor + (ipack, exs...) ) ) + { + return std::get::value-N>(ipack) + ->ifor( RPackNum::template mkFor(ipack, exs...) ); + } + }; @@ -382,6 +392,13 @@ namespace MultiArrayHelper out.emplace_back(*std::get(ip), std::get(bs)); } + template + static auto mkFor(const IndexPack& ipack, Exprs&&... exs) + -> decltype(std::get::value-1>(ipack) + ->ifor(exs...) ) + { + return std::get::value-1>(ipack)->ifor(exs...); + } }; diff --git a/src/ranges/single_range.h b/src/ranges/single_range.h index c6b901a..a825531 100644 --- a/src/ranges/single_range.h +++ b/src/ranges/single_range.h @@ -11,6 +11,10 @@ #include "ranges/index_base.h" #include "ranges/range_base.h" +#include "xfor/xfor.h" + +using MultiArrayHelper::For; + namespace MultiArrayTools { @@ -59,6 +63,9 @@ namespace MultiArrayTools std::string id(); void print(size_t offset); + + template + auto ifor(Expr&& ex) const -> For,Expr>; }; template @@ -239,6 +246,15 @@ namespace MultiArrayTools << "](" << IB::mRangePtr << "): " << meta() << std::endl; } + template + template + auto SingleIndex::ifor(Expr&& ex) const + -> For,Expr> + { + return For,Expr> + ( std::make_shared >(*this), ex ); + } + /******************** * SingleRange * diff --git a/src/xfor/xfor.h b/src/xfor/xfor.h index 01baeaa..18ffe8a 100644 --- a/src/xfor/xfor.h +++ b/src/xfor/xfor.h @@ -19,6 +19,8 @@ namespace MultiArrayHelper template For(const std::shared_ptr& indPtr, const Args&... args); + For(const std::shared_ptr& indPtr, Expr&& expr); + inline void operator()(size_t start = 0); private: @@ -42,6 +44,10 @@ namespace MultiArrayHelper For::For(const std::shared_ptr& indPtr, const Args&... args) : mIndPtr(indPtr), mExpr(args...) {} + template + For::For(const std::shared_ptr& indPtr, + Expr&& expr) : mIndPtr(indPtr), mExpr(expr) {} + template inline void For::operator()(size_t start) {