#ifndef __xfor_h__ #define __xfor_h__ #include #include #include namespace MultiArrayHelper { namespace { template using to_size_t = size_t; } template class For { public: For(For&& in) = default; For& operator=(For&& in) = default; template For(const std::shared_ptr& indPtr, std::tuple...>&& ext, const Args&... args); For(const std::shared_ptr& indPtr, Expr&& expr, std::tuple...>&& ext); inline void operator()(size_t mlast, const std::tuple...>& last) const; private: For() = default; mutable std::shared_ptr mIndPtr; const Expr mExpr; const std::tuple...> mExt; }; } // namespace MultiArrayHelper /* ========================= * * --- TEMPLATE CODE --- * * ========================= */ namespace MultiArrayHelper { template template 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, std::tuple...>&& ext) : mIndPtr(indPtr), mExpr(expr), mExt(ext) {} 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){ const size_t mnpos = mlast * max + ind.pos(); const std::tuple...> npos( /* !!! fancy code !!! */ ); mExpr(mnpos, npos); } } } // namespace MultiArrayHelper #endif