diff --git a/src/include/ranges/eindex.cc.h b/src/include/ranges/eindex.cc.h index a566125..f4d1dad 100644 --- a/src/include/ranges/eindex.cc.h +++ b/src/include/ranges/eindex.cc.h @@ -19,8 +19,7 @@ namespace CNORXZ template decltype(auto) EIndex::ifor(const Xpr& xpr, F&& f) const { - // TODO: EFor Function argument; meanwhile ignore unused function error!!! - return EFor(this->id(), xpr); + return EFor(this->id(), xpr, std::forward(f)); } } diff --git a/src/include/xpr/for.cc.h b/src/include/xpr/for.cc.h index 90d861c..3a3c672 100644 --- a/src/include/xpr/for.cc.h +++ b/src/include/xpr/for.cc.h @@ -389,31 +389,52 @@ namespace CNORXZ * EFor * ************/ - template - constexpr EFor::EFor(const IndexId& id, const Xpr& xpr) : + template + constexpr EFor::EFor(const IndexId& id, const Xpr& xpr, F&& f) : mId(id), mXpr(xpr), - mExt(mXpr.RootSteps(mId)) + mExt(mXpr.RootSteps(mId)), + mF(std::forward(f)) {} - template + template template - constexpr decltype(auto) EFor::operator()(const PosT& last) const + constexpr decltype(auto) EFor::operator()(const PosT& last) const { - auto pos = mkEPos(last, mExt); - return mXpr(pos); + if constexpr(std::is_same::type,NoF>::value){ + const auto pos = mkEPos(last, mExt); + mXpr(pos); + } + else { + typedef typename + std::remove_reference(SPos<0>(), mExt)))>::type OutT; + auto o = OutT(); + const auto pos = mkEPos(last, mExt); + mF(o, mXpr(pos)); + return o; + } } - template - constexpr decltype(auto) EFor::operator()() const + template + constexpr decltype(auto) EFor::operator()() const { - auto pos = mkEPos(SPos<0>(), mExt); - return mXpr(pos); + if constexpr(std::is_same::type,NoF>::value){ + const auto pos = mkEPos(SPos<0>(), mExt); + mXpr(pos); + } + else { + typedef typename + std::remove_reference(SPos<0>(), mExt)))>::type OutT; + auto o = OutT(); + const auto pos = mkEPos(SPos<0>(), mExt); + mF(o, mXpr(pos)); + return o; + } } - template + template template - constexpr decltype(auto) EFor::rootSteps(const IndexId& id) const + constexpr decltype(auto) EFor::rootSteps(const IndexId& id) const { return mXpr.rootSteps(id); } diff --git a/src/include/xpr/for.h b/src/include/xpr/for.h index 1ef46fd..ea56ade 100644 --- a/src/include/xpr/for.h +++ b/src/include/xpr/for.h @@ -149,13 +149,13 @@ namespace CNORXZ }; // Extension For (Vectorization) - template + template class EFor : public XprInterface> { public: DEFAULT_MEMBERS(EFor); - constexpr EFor(const IndexId& id, const Xpr& xpr); + constexpr EFor(const IndexId& id, const Xpr& xpr, F&& f); template constexpr decltype(auto) operator()(const PosT& last) const; @@ -170,6 +170,7 @@ namespace CNORXZ Xpr mXpr; typedef decltype(mXpr.rootSteps(mId)) XPosT; XPosT mExt; + F mF; }; }