EFor: F argument

This commit is contained in:
Christian Zimmermann 2023-06-04 17:31:47 +02:00
parent e9fde3d900
commit 52517675a5
3 changed files with 38 additions and 17 deletions

View file

@ -19,8 +19,7 @@ namespace CNORXZ
template <class Xpr, class F> template <class Xpr, class F>
decltype(auto) EIndex<MetaT,S>::ifor(const Xpr& xpr, F&& f) const decltype(auto) EIndex<MetaT,S>::ifor(const Xpr& xpr, F&& f) const
{ {
// TODO: EFor Function argument; meanwhile ignore unused function error!!! return EFor<S,0,Xpr>(this->id(), xpr, std::forward<F>(f));
return EFor<S,0,Xpr>(this->id(), xpr);
} }
} }

View file

@ -389,31 +389,52 @@ namespace CNORXZ
* EFor * * EFor *
************/ ************/
template <SizeT N, SizeT L, class Xpr> template <SizeT N, SizeT L, class Xpr, class F>
constexpr EFor<N,L,Xpr>::EFor(const IndexId<L>& id, const Xpr& xpr) : constexpr EFor<N,L,Xpr,F>::EFor(const IndexId<L>& id, const Xpr& xpr, F&& f) :
mId(id), mId(id),
mXpr(xpr), mXpr(xpr),
mExt(mXpr.RootSteps(mId)) mExt(mXpr.RootSteps(mId)),
mF(std::forward<F>(f))
{} {}
template <SizeT N, SizeT L, class Xpr> template <SizeT N, SizeT L, class Xpr, class F>
template <class PosT> template <class PosT>
constexpr decltype(auto) EFor<N,L,Xpr>::operator()(const PosT& last) const constexpr decltype(auto) EFor<N,L,Xpr,F>::operator()(const PosT& last) const
{ {
auto pos = mkEPos<N>(last, mExt); if constexpr(std::is_same<typename std::remove_reference<F>::type,NoF>::value){
return mXpr(pos); const auto pos = mkEPos<N>(last, mExt);
mXpr(pos);
}
else {
typedef typename
std::remove_reference<decltype(mXpr(mkEPos<N>(SPos<0>(), mExt)))>::type OutT;
auto o = OutT();
const auto pos = mkEPos<N>(last, mExt);
mF(o, mXpr(pos));
return o;
}
} }
template <SizeT N, SizeT L, class Xpr> template <SizeT N, SizeT L, class Xpr, class F>
constexpr decltype(auto) EFor<N,L,Xpr>::operator()() const constexpr decltype(auto) EFor<N,L,Xpr,F>::operator()() const
{ {
auto pos = mkEPos<N>(SPos<0>(), mExt); if constexpr(std::is_same<typename std::remove_reference<F>::type,NoF>::value){
return mXpr(pos); const auto pos = mkEPos<N>(SPos<0>(), mExt);
mXpr(pos);
}
else {
typedef typename
std::remove_reference<decltype(mXpr(mkEPos<N>(SPos<0>(), mExt)))>::type OutT;
auto o = OutT();
const auto pos = mkEPos<N>(SPos<0>(), mExt);
mF(o, mXpr(pos));
return o;
}
} }
template <SizeT N, SizeT L, class Xpr> template <SizeT N, SizeT L, class Xpr, class F>
template <SizeT I> template <SizeT I>
constexpr decltype(auto) EFor<N,L,Xpr>::rootSteps(const IndexId<I>& id) const constexpr decltype(auto) EFor<N,L,Xpr,F>::rootSteps(const IndexId<I>& id) const
{ {
return mXpr.rootSteps(id); return mXpr.rootSteps(id);
} }

View file

@ -149,13 +149,13 @@ namespace CNORXZ
}; };
// Extension For (Vectorization) // Extension For (Vectorization)
template <SizeT N, SizeT L, class Xpr> template <SizeT N, SizeT L, class Xpr, class F = NoF>
class EFor : public XprInterface<EFor<N,L,Xpr>> class EFor : public XprInterface<EFor<N,L,Xpr>>
{ {
public: public:
DEFAULT_MEMBERS(EFor); DEFAULT_MEMBERS(EFor);
constexpr EFor(const IndexId<L>& id, const Xpr& xpr); constexpr EFor(const IndexId<L>& id, const Xpr& xpr, F&& f);
template <class PosT> template <class PosT>
constexpr decltype(auto) operator()(const PosT& last) const; constexpr decltype(auto) operator()(const PosT& last) const;
@ -170,6 +170,7 @@ namespace CNORXZ
Xpr mXpr; Xpr mXpr;
typedef decltype(mXpr.rootSteps(mId)) XPosT; typedef decltype(mXpr.rootSteps(mId)) XPosT;
XPosT mExt; XPosT mExt;
F mF;
}; };
} }