diff --git a/src/xfor/index_for_utils.h b/src/xfor/index_for_utils.h index f26374f..cc8145d 100644 --- a/src/xfor/index_for_utils.h +++ b/src/xfor/index_for_utils.h @@ -4,10 +4,16 @@ #include "ranges/rheader.h" #include "xfor.h" +#include +#include namespace MultiArrayHelper { - + namespace { + template + using to_size_t = size_t; + } + template struct XFPackNum { @@ -24,7 +30,6 @@ namespace MultiArrayHelper { return XFPackNum::mkForTp(iTuple, std::get(iTuple), args...) } - }; template <> @@ -43,7 +48,6 @@ namespace MultiArrayHelper { return XFPackNum::value-1>::mkFor( std::get<0>(iTuple), args... ); } - }; } // end namespace MultiArrayHelper diff --git a/src/xfor/xfor.h b/src/xfor/xfor.h index 18ffe8a..4499b06 100644 --- a/src/xfor/xfor.h +++ b/src/xfor/xfor.h @@ -4,11 +4,16 @@ #include #include +#include namespace MultiArrayHelper { - - template + namespace { + template + using to_size_t = size_t; + } + + template class For { public: @@ -17,19 +22,24 @@ namespace MultiArrayHelper For& operator=(For&& in) = default; template - For(const std::shared_ptr& indPtr, const Args&... args); + For(const std::shared_ptr& indPtr, + std::tuple...>&& ext, const Args&... args); - For(const std::shared_ptr& indPtr, Expr&& expr); + For(const std::shared_ptr& indPtr, + Expr&& expr, std::tuple...>&& ext); - inline void operator()(size_t start = 0); + inline void operator()(size_t mlast, const std::tuple...>& last) const; private: For() = default; - std::shared_ptr mIndPtr; - Expr mExpr; + mutable std::shared_ptr mIndPtr; + const Expr mExpr; + const std::tuple...> mExt; }; + + } // namespace MultiArrayHelper /* ========================= * @@ -39,22 +49,29 @@ namespace MultiArrayHelper namespace MultiArrayHelper { - template + template template - For::For(const std::shared_ptr& indPtr, - const Args&... args) : mIndPtr(indPtr), mExpr(args...) {} + For::For(const std::shared_ptr& indPtr, + std::tuple...>&& ext, + const Args&... args) : + mIndPtr(indPtr), mExpr(args...), mExt(ext) {} - template - For::For(const std::shared_ptr& indPtr, - Expr&& expr) : mIndPtr(indPtr), mExpr(expr) {} + template + For::For(const std::shared_ptr& indPtr, + Expr&& expr, std::tuple...>&& ext) : + mIndPtr(indPtr), mExpr(expr), mExt(ext) {} - template - inline void For::operator()(size_t start) + template + inline void For::operator()(size_t mlast, + const std::tuple...>& last) const { + static const size_t opNum = sizeof...(Ops); auto& ind = *mIndPtr; const size_t max = ind.max(); for(ind = 0; ind.pos() != max; ++ind){ - mExpr(start * max + ind.pos()); // CHECK!! + const size_t mnpos = mlast * max + ind.pos(); + const std::tuple...> npos( /* !!! fancy code !!! */ ); + mExpr(mnpos, npos); } }