diff --git a/src/include/operation/op_types.cc.h b/src/include/operation/op_types.cc.h index 4df3517..6b327ff 100644 --- a/src/include/operation/op_types.cc.h +++ b/src/include/operation/op_types.cc.h @@ -4,10 +4,8 @@ #include "op_types.h" #include "xpr/pos_type.h" -#include "ranges/range_helper.h" #include "xpr/op_xpr.h" -#include "statics/static_for.h" - +#include "op_utility.h" namespace CNORXZ { @@ -17,20 +15,29 @@ namespace CNORXZ **********************/ template - template - auto COpInterface::c(const std::shared_ptr& ind) const + template + decltype(auto) COpInterface::c(F&& f, const Sptr& ind) const { - return Contraction(THIS(), ind); + return mkContraction(std::forward(f), THIS(), ind); + } + + template + template + decltype(auto) COpInterface::c(const Sptr& ind) const + { + return mkContraction([](auto& a, const auto& b) { a += b; }, + THIS(), ind); } template template constexpr auto a(F&& f, Args&&... args) const; - auto COpInterface::o(F&& f, Args&&... args) const + decltype(auto) COpInterface::o(F&& f, Args&&... args) const { - return Operation(f, THIS(), args...); + return Operation(std::forward(f), THIS(), args...); } + /********************* * OpInterface * *********************/ @@ -39,7 +46,7 @@ namespace CNORXZ template constexpr decltype(auto) OpInterface::ax(const Sptr& ind, F&& f, Args&&... args) { - return ind->ifor( SPos<1>(), OpXpr(f, THIS(), args...) ); + return ind->ifor( Operation(f, THIS(), args...) ); } template @@ -49,7 +56,7 @@ namespace CNORXZ return ax(ind, f, args...)(); } - + /*************** * COpRoot * ***************/ @@ -68,7 +75,7 @@ namespace CNORXZ template template - constexpr decltype(auto) COpRoot::get(const PosT& pos) const + constexpr decltype(auto) COpRoot::operator()(const PosT& pos) const { if constexpr(is_epos_type::value){ return vreg(mData,pos); // distinguish between consecutive/non-consecutive @@ -78,6 +85,12 @@ namespace CNORXZ } } + template + constexpr decltype(auto) COpRoot::operator()() const + { + return mData[0]; + } + template template constexpr decltype(auto) COpRoot::rootSteps(const IndexId& id) const @@ -85,13 +98,6 @@ namespace CNORXZ return mIndex->stepSize(id); } - template - template - constexpr decltype(auto) COpRoot::loop(Xpr&& xpr) const - { - return xpr; - } - template const T* COpRoot::data() const { @@ -140,7 +146,7 @@ namespace CNORXZ template template - constexpr decltype(auto) OpRoot::get(const PosT& pos) const + constexpr decltype(auto) OpRoot::operator()(const PosT& pos) const { if constexpr(is_epos_type::value){ return vreg(mData,pos); // distinguish between consecutive/non-consecutive @@ -150,6 +156,12 @@ namespace CNORXZ } } + template + constexpr decltype(auto) OpRoot::operator()() const + { + return mData[0]; + } + template template constexpr decltype(auto) OpRoot::rootSteps(const IndexId& id) const @@ -157,100 +169,41 @@ namespace CNORXZ return mIndex->stepSize(id); } - template - template - constexpr decltype(auto) OpRoot::loop(Xpr&& xpr) const; - { - return xpr; - } - /******************* * Operation * *******************/ - template - Operation::Operation(const Ops&... ops) : - mOps(ops...) - { - static_assert( FISSTATIC, "need function instance for non-static function" ); - } - - template - Operation::Operation(std::shared_ptr ff, - const Ops&... ops) : + template + Operation::Operation(F&& f, Ops&&... ops) : mOps(ops...), mF(ff) + {} + + template + template + inline decltype(auto) Operation::operator()(const PosT& pos) const { - static_assert( not FISSTATIC, "using instance of static function" ); + return pos_unpack_args(mF, pos, mOps); } - template - inline auto - mkOpExpr(std::shared_ptr f, const ETuple& pos, const OpTuple& ops, Args... args) + template + template + inline decltype(auto) Operation::operator()() const { - if constexpr(I == std::tuple_size{}){ - if constexpr(OpFunction::FISSTATIC){ - return OpFunction::apply(args...); - } - else { - (*f)(args...); - } - } - else { - typedef typename std::remove_reference(ops))>::type NextOpType; - return mkOpExpr - ( f, getX(pos), ops, args..., std::get(ops).get(pos)); - } + return exec(std::make_index_sequence{}); } - template - template - inline auto Operation::get(ET pos) const + template + constexpr decltype(auto) Operation::rootSteps(const IndexId& id) const { - return mkOpExpr<0>(mF, pos, mOps.mOps); + return mOps.rootSteps(id); } - template - template - inline auto Operation::vget(ET pos) const + template + constexpr decltype(auto) Operation::exec(std::index_sequence is) const { - return mkVOpExpr<0,V>(mF, pos, mOps.mOps); - } - - template - static inline void setOpPos(OpTuple& ot, const ETuple& et) - { - if constexpr(I != std::tuple_size{}){ - typedef typename std::remove_reference(ot))>::type NextOpType; - std::get( ot ).set( et ); - setOpPos(ot, getX(et)); - } - } - - template - template - inline Operation& Operation::set(ET pos) - { - setOpPos<0>(mOps.mOps,pos); - return *this; - } - - template - auto Operation::rootSteps(std::intptr_t iPtrNum) const - -> ExtType - { - return mOps.rootSteps(iPtrNum); - } - - template - template - auto Operation::loop(Expr exp) const - { - return sfor_m - ( [&](auto i){ return std::get(mOps.mOps); }, - [&](auto f, auto next) { return f.loop(next); }, - exp ); + return mF( std::get(mOps)() ... ); } @@ -265,11 +218,17 @@ namespace CNORXZ template template - constexpr decltype(auto) Contraction::get(const PosT& pos) const + constexpr decltype(auto) Contraction::operator()(const PosT& pos) const { return mCXpr(pos); } + template + constexpr decltype(auto) Contraction::operator()() const + { + return mCXpr(); + } + template template constexpr decltype(auto) Contraction::rootSteps(const IndexId& id) const; @@ -277,18 +236,11 @@ namespace CNORXZ return mCXpr.stepSize(id); } - template - template - constexpr decltype(auto) Contraction::loop(Xpr&& xpr) const - { - return xpr; - } - template constexpr decltype(auto) mkContracion(F&& f, Op&& op, const Sptr& i) { - typedef decltype(i->ifor( mkOpXpr( f, op ) )) CXprT; - return Contraction( i->ifor( mkOpXpr( f, op ) ) ); + typedef decltype(i->ifor( op, f )) CXprT; // TODO: implement ifor with func arg!!! + return Contraction( i->ifor( op, f ) ); } } diff --git a/src/include/operation/op_types.h b/src/include/operation/op_types.h index 9b25aab..e5ef07c 100644 --- a/src/include/operation/op_types.h +++ b/src/include/operation/op_types.h @@ -10,30 +10,22 @@ namespace CNORXZ template - class COpInterface + class COpInterface : public XprInterface { public: OpT& THIS() { return static_cast(*this); } const OpT& THIS() const { return static_cast(*this); } + template + constexpr decltype(auto) c(F&& f, const Sptr& ind) const; + template - constexpr auto c(const Sptr& ind) const; + constexpr decltype(auto) c(const Sptr& ind) const; template - constexpr auto o(F&& f, Args&&... args) const; + constexpr decltype(auto) o(F&& f, Args&&... args) const; - template - constexpr decltype(auto) get(const PosT& pos) const - { return THIS().get(pos); } - - template - constexpr decltype(auto) rootSteps(const IndexId& id) const - { return THIS().rootSteps(id); } - - template - constexpr decltype(auto) loop(Xpr&& exp) const - { return THIS().loop(exp); } }; template @@ -72,14 +64,13 @@ namespace CNORXZ constexpr COpRoot(const T* data, const Sptr& ind); template - constexpr decltype(auto) get(const PosT& pos) const; + constexpr decltype(auto) operator()(const PosT& pos) const; + + constexpr decltype(auto) operator()() const; template constexpr decltype(auto) rootSteps(const IndexId& id) const; - template - constexpr decltype(auto) loop(Xpr&& xpr) const; - const T* data() const; private: @@ -114,14 +105,13 @@ namespace CNORXZ constexpr OpRoot& operator=(const OpRoot& in); template - constexpr decltype(auto) get(const PosT& pos) const; + constexpr decltype(auto) operator()(const PosT& pos) const; + + constexpr decltype(auto) operator()() const; template constexpr decltype(auto) rootSteps(const IndexId& id) const; - template - constexpr decltype(auto) loop(Xpr&& exp) const; - T* data() const; private: @@ -140,15 +130,17 @@ namespace CNORXZ constexpr Operation(F&& f, Ops&&... ops); template - constexpr decltype(auto) get(const PosT& pos) const; + constexpr decltype(auto) operator()(const PosT& pos) const; + + constexpr decltype(auto) operator()() const; template - constexpr decltype(auto) rootSteps(const IndexId& id) const - - template - constexpr decltype(auto) loop(Xpr&& xpr) const; + constexpr decltype(auto) rootSteps(const IndexId& id) const; private: + template + constexpr decltype(auto) exec(std::index_sequence is) const; + Tuple mOps; F mF; @@ -163,14 +155,13 @@ namespace CNORXZ constexpr Contraction(CXpr&& cxpr); template - constexpr decltype(auto) get(const PosT& pos) const; + constexpr decltype(auto) operator()(const PosT& pos) const; + + constexpr decltype(auto) operator()() const; template constexpr decltype(auto) rootSteps(const IndexId& id) const; - template - constexpr decltype(auto) loop(Xpr&& xpr) const; - private: CXpr mCXpr; Sptr mInd; diff --git a/src/include/operation/op_xpr.cc.h b/src/include/operation/op_xpr.cc.h deleted file mode 100644 index 8488766..0000000 --- a/src/include/operation/op_xpr.cc.h +++ /dev/null @@ -1,49 +0,0 @@ - -#ifndef __cxz_op_expr_cc_h__ -#define __cxz_op_expr_cc_h__ - -#include "op_expr.h" -#include "op_utility.h" - -namespace CNORXZ -{ - template - constexpr OpXpr::OpXpr(F&& f, Ops&&... ops) : - mF(std::forward(f)), - mOps(ops...) - { - static_assert((is_operation::value and ...), "got non-op type"); - } - - template - template - inline SizeT OpXpr::operator()(const PosT& last) const - { - pos_unpack_args(mF,last,mOps); // utility function (to be implemented) - // depending on whether Ops[N] is static or not call statically or dynamically .next() - return 0; - } - - template - inline SizeT OpXpr::operator()() const - { - return 0; - } - - template - template - constexpr decltype(auto) OpXpr::rootSteps(const IndexId& id) const - { - return rootStepsI(id, std::make_index_sequence{}); - } - - template - template - constexpr decltype(auto) OpXpr::rootStepsI(const IndexId& id, std::index_sequence is) const - { - return (std::get(mOps).rootSteps(id) << ...); - // TODO: implement a << b which is a.extend(b)!! - } -} - -#endif diff --git a/src/include/operation/op_xpr.h b/src/include/operation/op_xpr.h deleted file mode 100644 index 727f283..0000000 --- a/src/include/operation/op_xpr.h +++ /dev/null @@ -1,37 +0,0 @@ - -#ifndef __cxz_op_expr_h__ -#define __cxz_op_expr_h__ - -#include "base/base.h" -#include "operation/operation_base.h" -#include "xpr/xpr_base.h" - -namespace CNORXZ -{ - - template - class OpXpr - { - private: - F mF; - Tuple mOps; - - template - constexpr decltype(auto) rootStepsI(const IndexId& id, std::index_sequence is) const; - - public: - DEFAULT_MEMBERS(OpXpr); - - constexpr OpXpr(F&& f, Ops&&... ops); - - template - inline SizeT operator()(const PosT& last) const; - - inline SizeT operator()() const; - - template - constexpr decltype(auto) rootSteps(const IndexId& id) const; - }; -} - -#endif diff --git a/src/include/ranges/crange.cc.h b/src/include/ranges/crange.cc.h index e07ad5f..6aa0e12 100644 --- a/src/include/ranges/crange.cc.h +++ b/src/include/ranges/crange.cc.h @@ -9,7 +9,7 @@ namespace CNORXZ template decltype(auto) CIndex::ifor(const Xpr& xpr) const { - return For<0,Xpr>(this->max(), this->id(), xpr); + return For<0,Xpr>(this->max(), this->id(), xpr, NoF()); } } diff --git a/src/include/ranges/dindex.h b/src/include/ranges/dindex.h index e4231d2..9d4817a 100644 --- a/src/include/ranges/dindex.h +++ b/src/include/ranges/dindex.h @@ -50,7 +50,7 @@ namespace CNORXZ DType meta() const; DIndex& at(const DType& meta); - DXpr ifor(const DXpr& xpr) const; + DXpr ifor(const DXpr& xpr) const; private: XIndexPtr mI; diff --git a/src/include/ranges/xindex.cc.h b/src/include/ranges/xindex.cc.h index b445046..655d6c0 100644 --- a/src/include/ranges/xindex.cc.h +++ b/src/include/ranges/xindex.cc.h @@ -155,9 +155,9 @@ namespace CNORXZ } template - DXpr XIndex::ifor(const DXpr& xpr) const + DXpr XIndex::ifor(const DXpr& xpr) const { - return DXpr(mI->ifor(xpr)); + return DXpr(mI->ifor(xpr)); } } diff --git a/src/include/ranges/xindex.h b/src/include/ranges/xindex.h index 38b359b..1fe2a89 100644 --- a/src/include/ranges/xindex.h +++ b/src/include/ranges/xindex.h @@ -42,7 +42,7 @@ namespace CNORXZ virtual DType meta() const = 0; virtual XIndexBase& at(const DType& meta) = 0; - virtual DXpr ifor(const DXpr& xpr) const = 0; + virtual DXpr ifor(const DXpr& xpr) const = 0; }; //Sptr& operator++(Sptr& i); @@ -91,7 +91,7 @@ namespace CNORXZ virtual DType meta() const override final; virtual XIndexBase& at(const DType& meta) override final; - virtual DXpr ifor(const DXpr& xpr) const override final; + virtual DXpr ifor(const DXpr& xpr) const override final; private: IndexPtr mI; diff --git a/src/include/ranges/yrange.h b/src/include/ranges/yrange.h index 58ae0a8..95f9b1d 100644 --- a/src/include/ranges/yrange.h +++ b/src/include/ranges/yrange.h @@ -51,7 +51,7 @@ namespace CNORXZ DType meta() const; YIndex& at(const DType& meta); - DXpr ifor(const DXpr& xpr) const; + DXpr ifor(const DXpr& xpr) const; private: diff --git a/src/include/xpr/for.cc.h b/src/include/xpr/for.cc.h index 58ec16e..14b3948 100644 --- a/src/include/xpr/for.cc.h +++ b/src/include/xpr/for.cc.h @@ -8,42 +8,63 @@ namespace CNORXZ { + /************* + * ZeroF * + *************/ + + template + constexpr decltype(auto) ZeroF::operator()(const T&... as) const + { + return 0; + } + + template + constexpr decltype(auto) NoF::operator()(const T&... as) const + { + return; + } + /*********** * For * ***********/ - template - constexpr For::For(SizeT size, const IndexId& id, const Xpr& xpr) : + template + constexpr For::For(SizeT size, const IndexId& id, const Xpr& xpr, F&& f) : mSize(size), mId(id), mXpr(xpr), - mExt(mXpr.rootSteps(mId)) + mExt(mXpr.rootSteps(mId)), + mF(f) {} - template + template template - inline SizeT For::operator()(const PosT& last) const + inline decltype(auto) For::operator()(const PosT& last) const { + typedef typename std::remove_reference::type OutT; + auto o = OutT(); for(SizeT i = 0; i != mSize; ++i){ const auto pos = last + mExt * UPos(i); - mXpr(pos); + mF(o, mXpr(pos)); } - return 0; + return o; } - template - inline SizeT For::operator()() const + template + inline decltype(auto) For::operator()() const { + typedef typename std::remove_reference::type OutT; + auto o = OutT(); for(SizeT i = 0; i != mSize; ++i){ const auto pos = mExt * UPos(i); - mXpr(pos); + mF(o, mXpr(pos)); } - return 0; + return o; } - template + template template - inline decltype(auto) For::rootSteps(const IndexId& id) const + inline decltype(auto) For::rootSteps(const IndexId& id) const { return mXpr.rootSteps(id); } @@ -53,60 +74,61 @@ namespace CNORXZ * SFor * ************/ - template - constexpr SFor::SFor(const IndexId& id, const Xpr& xpr) : + template + constexpr SFor::SFor(const IndexId& id, const Xpr& xpr, F&& f) : mId(id), mXpr(xpr), - mExt(mXpr.RootSteps(mId)) + mExt(mXpr.RootSteps(mId)), + mF(f) {} - template + template template - constexpr SizeT SFor::operator()(const PosT& last) const + constexpr decltype(auto) SFor::operator()(const PosT& last) const { return exec<0>(last); } - template - constexpr SizeT SFor::operator()() const + template + constexpr decltype(auto) SFor::operator()() const { return exec<0>(); } - template + template template - constexpr decltype(auto) SFor::rootSteps(const IndexId& id) const + constexpr decltype(auto) SFor::rootSteps(const IndexId& id) const { return mXpr.rootSteps(id); } - template + template template - constexpr SizeT SFor::exec(const PosT& last) const + constexpr decltype(auto) SFor::exec(const PosT& last) const { constexpr SPos i; const auto pos = last + mExt * i; - mXpr(pos); + auto o = mXpr(pos); if constexpr(I < N-1){ - return exec(last); + return mF(o,exec(last)); } else { - return 0; + return o; } } - template + template template - constexpr SizeT SFor::exec() const + constexpr decltype(auto) SFor::exec() const { constexpr SPos i; const auto pos = mExt * i; - mXpr(pos); + auto o = mXpr(pos); if constexpr(I < N-1){ - return exec(); + return mF(o,exec()); } else { - return 0; + return o; } } @@ -114,12 +136,13 @@ namespace CNORXZ * TFor * ************/ - template - constexpr TFor::TFor(SizeT size, const IndexId& id, const Xpr& xpr) : + template + constexpr TFor::TFor(SizeT size, const IndexId& id, const Xpr& xpr, F&& f) : mSize(size), mId(id), mXpr(xpr), - mExt(mXpr.rootSteps(mId)) + mExt(mXpr.rootSteps(mId)), + mF(f) { // check for write access!!! /* @@ -130,12 +153,18 @@ namespace CNORXZ */ } - template + template template - inline SizeT TFor::operator()(const PosT& last) const + inline decltype(auto) TFor::operator()(const PosT& last) const { + typedef typename std::remove_reference::type OutT; int i = 0; const int size = static_cast(mSize); + Vector ov; + if constexpr(not std::is_same::value){ + // replace if statement by "does s.th. non-trivial" + ov.resize(mSize); + } #pragma omp parallel private(i) { auto xpr = mXpr; @@ -145,14 +174,27 @@ namespace CNORXZ xpr(pos); } } - return 0; + OutT o; + if constexpr(not std::is_same::value){ + // replace if statement by "does s.th. non-trivial" + for(SizeT i = 0; i != mSize; ++i){ + mF(o, ov[i]); + } + } + return o; } - template - inline SizeT TFor::operator()() const + template + inline decltype(auto) TFor::operator()() const { + typedef typename std::remove_reference::type OutT; int i = 0; const int size = static_cast(mSize); + Vector ov; + if constexpr(not std::is_same::value){ + // replace if statement by "does s.th. non-trivial" + ov.resize(mSize); + } #pragma omp parallel private(i) { auto xpr = mXpr; @@ -162,12 +204,19 @@ namespace CNORXZ xpr(pos); } } - return 0; + OutT o; + if constexpr(not std::is_same::value){ + // replace if statement by "does s.th. non-trivial" + for(SizeT i = 0; i != mSize; ++i){ + mF(o, ov[i]); + } + } + return o; } - template + template template - inline decltype(auto) TFor::rootSteps(const IndexId& id) const + inline decltype(auto) TFor::rootSteps(const IndexId& id) const { return mXpr.rootSteps(id); } @@ -186,14 +235,14 @@ namespace CNORXZ template template - constexpr SizeT EFor::operator()(const PosT& last) const + constexpr decltype(auto) EFor::operator()(const PosT& last) const { auto pos = mkEPos(last, mExt); return mXpr(pos); } template - constexpr SizeT EFor::operator()() const + constexpr decltype(auto) EFor::operator()() const { auto pos = mkEPos(SPos<0>(), mExt); return mXpr(pos); diff --git a/src/include/xpr/for.h b/src/include/xpr/for.h index 8b7771e..0759ad8 100644 --- a/src/include/xpr/for.h +++ b/src/include/xpr/for.h @@ -7,19 +7,32 @@ namespace CNORXZ { + class ZeroF + { + public: + template + constexpr decltype(auto) operator()(const T&... as) const; + }; - template - class For : public XprInterface> + class NoF + { + public: + template + constexpr decltype(auto) operator()(const T&... as) const; + }; + + template + class For : public XprInterface> { public: DEFAULT_MEMBERS(For); - constexpr For(SizeT size, const IndexId& id, const Xpr& xpr); + constexpr For(SizeT size, const IndexId& id, const Xpr& xpr, F&& f); template - inline SizeT operator()(const PosT& last) const; + inline decltype(auto) operator()(const PosT& last) const; - inline SizeT operator()() const; + inline decltype(auto) operator()() const; template inline decltype(auto) rootSteps(const IndexId& id) const; @@ -30,22 +43,23 @@ namespace CNORXZ Xpr mXpr; typedef decltype(mXpr.rootSteps(mId)) XPosT; XPosT mExt; - + F mF; }; + // unrolled loop: - template - class SFor : public XprInterface> + template + class SFor : public XprInterface> { public: DEFAULT_MEMBERS(SFor); - constexpr SFor(const IndexId& id, const Xpr& xpr); + constexpr SFor(const IndexId& id, const Xpr& xpr, F&& f); template - constexpr SizeT operator()(const PosT& last) const; + constexpr decltype(auto) operator()(const PosT& last) const; - constexpr SizeT operator()() const; + constexpr decltype(auto) operator()() const; template constexpr decltype(auto) rootSteps(const IndexId& id) const; @@ -53,32 +67,33 @@ namespace CNORXZ private: template - constexpr SizeT exec(const PosT& last) const; + constexpr decltype(auto) exec(const PosT& last) const; template - constexpr SizeT exec() const; + constexpr decltype(auto) exec() const; IndexId mId; Xpr mXpr; typedef decltype(mXpr.RootSteps(mId)) XPosT; XPosT mExt; + F mF; }; // multi-threading - template - class TFor : public XprInterface> + template + class TFor : public XprInterface> { public: DEFAULT_MEMBERS(TFor); - constexpr TFor(SizeT size, const IndexId& id, const Xpr& xpr); + constexpr TFor(SizeT size, const IndexId& id, const Xpr& xpr, F&& f); template - inline SizeT operator()(const PosT& last) const; + inline decltype(auto) operator()(const PosT& last) const; - inline SizeT operator()() const; + inline decltype(auto) operator()() const; template inline decltype(auto) rootSteps(const IndexId& id) const; @@ -89,7 +104,7 @@ namespace CNORXZ Xpr mXpr; typedef decltype(mXpr.rootSteps(mId)) XPosT; XPosT mExt; - + F mF; }; // Extension For (Vectorization) @@ -102,9 +117,9 @@ namespace CNORXZ constexpr EFor(const IndexId& id, const Xpr& xpr); template - constexpr SizeT operator()(const PosT& last) const; + constexpr decltype(auto) operator()(const PosT& last) const; - constexpr SizeT operator()() const; + constexpr decltype(auto) operator()() const; template constexpr decltype(auto) rootSteps(const IndexId& id) const; diff --git a/src/include/xpr/for_type.h b/src/include/xpr/for_type.h deleted file mode 100644 index 6833c99..0000000 --- a/src/include/xpr/for_type.h +++ /dev/null @@ -1,23 +0,0 @@ - -#ifndef __cxz_for_type_h__ -#define __cxz_for_type_h__ - -namespace CNORXZInternal -{ - - enum class ForType { - DEFAULT = 0, - HIDDEN = 1 - }; - - template - class For; - - template - class PFor; - - -} // end namespace CNORXZInternal - - -#endif diff --git a/src/include/xpr/xpr_base.cc.h b/src/include/xpr/xpr_base.cc.h index 99da39a..dcc24c5 100644 --- a/src/include/xpr/xpr_base.cc.h +++ b/src/include/xpr/xpr_base.cc.h @@ -11,31 +11,31 @@ namespace CNORXZ * VXpr * ************/ - template - VXpr::VXpr(const XprInterface& a) : + template + VXpr::VXpr(const XprInterface& a) : Xpr(a.THIS()) {} - template - Uptr VXpr::copy() const + template + Uptr> VXpr::copy() const { - return std::make_unique>(*this); + return std::make_unique>(*this); } - template - SizeT VXpr::vexec(const DPos& last) const + template + T VXpr::vexec(const DPos& last) const { return (*this)(last); } - template - SizeT VXpr::vexec() const + template + T VXpr::vexec() const { return (*this)(); } - template - DPos VXpr::vrootSteps(const IndexId<0>& id) const + template + DPos VXpr::vrootSteps(const IndexId<0>& id) const { return DPos(this->rootSteps(id)); } @@ -44,25 +44,29 @@ namespace CNORXZ * DXpr * ************/ + template template - DXpr::DXpr(const Xpr& a) : - ObjHandle(std::make_unique>(a)) + DXpr::DXpr(const Xpr& a) : + ObjHandle>(std::make_unique>(a)) {} - inline SizeT DXpr::operator()(const DPos& last) const + template + inline T DXpr::operator()(const DPos& last) const { - return mC->vexec(last); + return VB::mC->vexec(last); } - inline SizeT DXpr::operator()() const + template + inline T DXpr::operator()() const { - return mC->vexec(); + return VB::mC->vexec(); } + template template - inline DPos DXpr::rootSteps(const IndexId& id) const + inline DPos DXpr::rootSteps(const IndexId& id) const { - return mC->vrootSteps(IndexId<0>(id.id())); + return VB::mC->vrootSteps(IndexId<0>(id.id())); } } diff --git a/src/include/xpr/xpr_base.h b/src/include/xpr/xpr_base.h index aad448d..53bf760 100644 --- a/src/include/xpr/xpr_base.h +++ b/src/include/xpr/xpr_base.h @@ -19,53 +19,57 @@ namespace CNORXZ inline const Xpr& THIS() const { return static_cast(*this); } template - inline SizeT operator()(const PosT& last) const { return THIS()(last); } + constexpr decltype(auto) operator()(const PosT& last) const { return THIS()(last); } - inline SizeT operator()() const { return THIS()(); } + constexpr decltype(auto) operator()() const { return THIS()(); } template constexpr decltype(auto) rootSteps(const IndexId& id) const { return THIS().rootSteps(id); } }; + template class VXprBase { public: DEFAULT_MEMBERS(VXprBase); - virtual Uptr copy() const = 0; + virtual Uptr> copy() const = 0; - virtual SizeT vexec(const DPos& last) const = 0; - virtual SizeT vexec() const = 0; + virtual T vexec(const DPos& last) const = 0; + virtual T vexec() const = 0; virtual DPos vrootSteps(const IndexId<0>& id) const = 0; }; - template - class VXpr : public VXprBase, public Xpr + template + class VXpr : public VXprBase, public Xpr { public: DEFAULT_MEMBERS(VXpr); VXpr(const XprInterface& a); - virtual Uptr copy() const override final; + virtual Uptr> copy() const override final; - virtual SizeT vexec(const DPos& last) const override final; - virtual SizeT vexec() const override final; + virtual T vexec(const DPos& last) const override final; + virtual T vexec() const override final; virtual DPos vrootSteps(const IndexId<0>& id) const override final; }; - class DXpr : public ObjHandle, - public XprInterface + template + class DXpr : public ObjHandle>, + public XprInterface> { public: + typedef ObjHandle> VB; + DEFAULT_MEMBERS(DXpr); template explicit DXpr(const Xpr& a); - inline SizeT operator()(const DPos& last) const; - inline SizeT operator()() const; + inline T operator()(const DPos& last) const; + inline T operator()() const; template inline DPos rootSteps(const IndexId& id) const; diff --git a/src/lib/ranges/dindex.cc b/src/lib/ranges/dindex.cc index e2ae9fb..c31d910 100644 --- a/src/lib/ranges/dindex.cc +++ b/src/lib/ranges/dindex.cc @@ -138,9 +138,9 @@ namespace CNORXZ return *this; } - DXpr DIndex::ifor(const DXpr& xpr) const + DXpr DIndex::ifor(const DXpr& xpr) const { - return DXpr(mI->ifor(xpr)); + return DXpr(mI->ifor(xpr)); } } diff --git a/src/lib/ranges/yrange.cc b/src/lib/ranges/yrange.cc index 3789c99..f1f09f8 100644 --- a/src/lib/ranges/yrange.cc +++ b/src/lib/ranges/yrange.cc @@ -171,10 +171,10 @@ namespace CNORXZ return *this; } - DXpr YIndex::ifor(const DXpr& xpr) const + DXpr YIndex::ifor(const DXpr& xpr) const { assert(0); - return DXpr(); + return DXpr(); } /**********************