diff --git a/src/multi_array_operation.h b/src/multi_array_operation.h index 01c42f4..1cf1f72 100644 --- a/src/multi_array_operation.h +++ b/src/multi_array_operation.h @@ -95,19 +95,20 @@ namespace MultiArrayTools public: static size_t layer() { return 0; } - static const size_t LAYER = 0; - static const size_t SIZE = OpClass::SIZE; - typedef decltype(mSec.rootSteps()) ETuple; + static constexpr size_t LAYER = 0; + static constexpr size_t SIZE = OpClass::SIZE; + typedef decltype(mSec.rootSteps()) ExtType; AssignmentExpr(OperationMaster& m, const OpClass& sec); + AssignmentExpr(const AssignmentExpr& in) = default; AssignmentExpr(AssignmentExpr&& in) = default; //AssignmentExpr& operator=(const AssignmentExpr&& in) = default; - //inline void operator()(size_t start = 0); - inline void operator()(size_t start, const ETuple& last); + inline void operator()(size_t start = 0); + inline void operator()(size_t start, ExtType last); - ETuple rootSteps(std::intptr_t iPtrNum = 0); + auto rootSteps(std::intptr_t iPtrNum = 0) -> ExtType; }; @@ -178,7 +179,7 @@ namespace MultiArrayTools std::tuple rootSteps(std::intptr_t iPtrNum = 0) const; // nullptr for simple usage with decltype template - Expr&& loop(Expr&& exp) const; + Expr loop(Expr exp) const; private: @@ -230,7 +231,7 @@ namespace MultiArrayTools std::tuple rootSteps(std::intptr_t iPtrNum = 0) const; // nullptr for simple usage with decltype template - Expr&& loop(Expr&& exp) const; + Expr loop(Expr exp) const; private: @@ -322,8 +323,8 @@ namespace MultiArrayTools -> decltype(PackNum::mkStepTuple(iPtrNum, mOps)); template - auto loop(Expr&& exp) const - -> decltype(PackNum::mkLoop( mOps, std::forward( exp ) ))&&; + auto loop(Expr exp) const + -> decltype(PackNum::mkLoop( mOps, exp)); }; @@ -488,13 +489,13 @@ namespace MultiArrayTools template inline void OperationMaster::AssignmentExpr:: - operator()(size_t start, const ETuple& last) + operator()(size_t start, ExtType last) { - mM.get(start) = mSec.template get(last); + mM.get(start) = mSec.template get(last); } template - typename OperationMaster::AssignmentExpr::ETuple + typename OperationMaster::AssignmentExpr::ExtType OperationMaster::AssignmentExpr:: rootSteps(std::intptr_t iPtrNum) { @@ -681,9 +682,9 @@ namespace MultiArrayTools template template - Expr&& ConstOperationRoot::loop(Expr&& exp) const + Expr ConstOperationRoot::loop(Expr exp) const { - return std::forward(exp); + return exp; } /*********************** @@ -784,9 +785,9 @@ namespace MultiArrayTools template template - Expr&& OperationRoot::loop(Expr&& exp) const + Expr OperationRoot::loop(Expr exp) const { - return std::forward(exp); + return exp; } /******************* @@ -842,13 +843,10 @@ namespace MultiArrayTools template template - auto Operation::loop(Expr&& exp) const - -> decltype(PackNum::mkLoop( mOps, std::forward( exp ) ))&& + auto Operation::loop(Expr exp) const + -> decltype(PackNum::mkLoop( mOps, exp )) { - typedef decltype(PackNum::mkLoop( mOps, std::forward( exp ) ) ) - LType; - return std::forward - ( PackNum::mkLoop( mOps, std::forward( exp ) ) ); + return PackNum::mkLoop( mOps, exp ); } @@ -904,11 +902,9 @@ namespace MultiArrayTools template template - auto Contraction::loop(Expr&& exp) const -> decltype(mInd->iforh(exp))&& + auto Contraction::loop(Expr exp) const -> decltype(mInd->iforh(exp)) { - typedef decltype(mInd->iforh(exp)) LType; - LType&& loop = mInd->iforh(exp); - return std::forward( loop ); + return mInd->iforh(exp); } } diff --git a/src/ranges/container_range.h b/src/ranges/container_range.h index 8d1240c..eb69649 100644 --- a/src/ranges/container_range.h +++ b/src/ranges/container_range.h @@ -90,11 +90,11 @@ namespace MultiArrayTools void print(size_t offset); template - auto ifor(Exprs&& exs) const + auto ifor(Exprs exs) const -> decltype(RPackNum::mkFor(mIPack, exs)); template - auto iforh(Exprs&& exs) const + auto iforh(Exprs exs) const -> decltype(RPackNum::mkForh(mIPack, exs)); }; @@ -377,7 +377,7 @@ namespace MultiArrayTools template template - auto ContainerIndex::ifor(Exprs&& exs) const + auto ContainerIndex::ifor(Exprs exs) const -> decltype(RPackNum::mkFor(mIPack, exs)) { return RPackNum::mkFor(mIPack, exs); @@ -385,7 +385,7 @@ namespace MultiArrayTools template template - auto ContainerIndex::iforh(Exprs&& exs) const + auto ContainerIndex::iforh(Exprs exs) const -> decltype(RPackNum::mkForh(mIPack, exs)) { return RPackNum::mkForh(mIPack, exs); diff --git a/src/ranges/multi_range.h b/src/ranges/multi_range.h index 82e0f4a..23dfb84 100644 --- a/src/ranges/multi_range.h +++ b/src/ranges/multi_range.h @@ -106,11 +106,11 @@ namespace MultiArrayTools void print(size_t offset); template - auto ifor(Exprs&& exs) const + auto ifor(Exprs exs) const -> decltype(RPackNum::mkFor(mIPack, exs)); template - auto iforh(Exprs&& exs) const + auto iforh(Exprs exs) const -> decltype(RPackNum::mkForh(mIPack, exs)); }; @@ -422,7 +422,7 @@ namespace MultiArrayTools template template - auto MultiIndex::ifor(Exprs&& exs) const + auto MultiIndex::ifor(Exprs exs) const -> decltype(RPackNum::mkFor(mIPack, exs)) { return RPackNum::mkFor(mIPack, exs); @@ -430,7 +430,7 @@ namespace MultiArrayTools template template - auto MultiIndex::iforh(Exprs&& exs) const + auto MultiIndex::iforh(Exprs exs) const -> decltype(RPackNum::mkForh(mIPack, exs)) { return RPackNum::mkForh(mIPack, exs); diff --git a/src/ranges/rpack_num.h b/src/ranges/rpack_num.h index c49c160..d0e44c9 100644 --- a/src/ranges/rpack_num.h +++ b/src/ranges/rpack_num.h @@ -234,7 +234,7 @@ namespace MultiArrayHelper } template - static auto mkFor(const IndexPack& ipack, Exprs&& exs) + static auto mkFor(const IndexPack& ipack, Exprs exs) -> decltype(std::get::value-N-1>(ipack) ->ifor( RPackNum::mkFor(ipack, exs) ) ) { @@ -243,7 +243,7 @@ namespace MultiArrayHelper } template - static auto mkForh(const IndexPack& ipack, Exprs&& exs) + static auto mkForh(const IndexPack& ipack, Exprs exs) -> decltype(std::get::value-N-1>(ipack) ->iforh( RPackNum::mkForh(ipack, exs) ) ) { @@ -415,7 +415,7 @@ namespace MultiArrayHelper } template - static auto mkFor(const IndexPack& ipack, Exprs&& exs) + static auto mkFor(const IndexPack& ipack, Exprs exs) -> decltype(std::get::value-1>(ipack) ->ifor(exs) ) { @@ -423,7 +423,7 @@ namespace MultiArrayHelper } template - static auto mkForh(const IndexPack& ipack, Exprs&& exs) + static auto mkForh(const IndexPack& ipack, Exprs exs) -> decltype(std::get::value-1>(ipack) ->iforh(exs) ) { diff --git a/src/ranges/single_range.h b/src/ranges/single_range.h index 51f9e31..8bd3b4d 100644 --- a/src/ranges/single_range.h +++ b/src/ranges/single_range.h @@ -66,11 +66,11 @@ namespace MultiArrayTools void print(size_t offset); template - auto ifor(Expr&& ex) const + auto ifor(Expr ex) const -> For,Expr>; template - auto iforh(Expr&& ex) const + auto iforh(Expr ex) const -> For,Expr,ForType::HIDDEN>; }; @@ -108,7 +108,7 @@ namespace MultiArrayTools friend SingleRangeFactory; - static const bool defaultable = false; + static constexpr bool defaultable = false; protected: @@ -255,20 +255,20 @@ namespace MultiArrayTools template template - auto SingleIndex::ifor(Expr&& ex) const + auto SingleIndex::ifor(Expr ex) const -> For,Expr> { //static const size_t LAYER = typename Expr::LAYER; - return For,Expr>(this, std::forward( ex )); + return For,Expr>(this, ex); } template template - auto SingleIndex::iforh(Expr&& ex) const + auto SingleIndex::iforh(Expr ex) const -> For,Expr,ForType::HIDDEN> { //static const size_t LAYER = typename Expr::LAYER; - return For,Expr,ForType::HIDDEN>(this, std::forward( ex )); + return For,Expr,ForType::HIDDEN>(this, ex); } diff --git a/src/xfor/exttype.h b/src/xfor/exttype.h new file mode 100644 index 0000000..15ddb5b --- /dev/null +++ b/src/xfor/exttype.h @@ -0,0 +1,178 @@ + +#ifndef __exttype_h__ +#define __exttype_h__ + +#include + +namespace XFOR +{ + + template + class MExt + { + private: + + size_t mExt = 0u; + X mNext; + + public: + + static constexpr size_t NUM = X::NUM + 1; + + MExt() = default; + MExt(const MExt& in) = default; + MExt& operator=(const MExt& in) = default; + MExt(MExt&& in) = default; + MExt& operator=(MExt&& in) = default; + + inline MExt(size_t ext, X next); + + template + inline MExt(const std::array& arr); + + inline size_t val() const; + inline const X& next() const; + + inline MExt operator+(const MExt& in) const; + inline MExt operator*(size_t in) const; + + }; + + template <> + class MExt + { + private: + + size_t mExt = 0u; + + public: + + static constexpr size_t NUM = 0; + + MExt() = default; + MExt(const MExt& in) = default; + MExt& operator=(const MExt& in) = default; + MExt(MExt&& in) = default; + MExt& operator=(MExt&& in) = default; + + inline MExt(size_t ext); + + template + inline MExt(const std::array& arr); + + inline size_t val() const; + + inline MExt operator+(const MExt& in) const; + inline MExt operator*(size_t in) const; + + }; + + + template + struct Getter + { + template + static inline size_t get(const ExtType& et) + { + return Getter::get(et.next()); + } + + template + static inline auto getX(const ExtType& et) + -> decltype(Getter::get(et.next())) + { + return Getter::getX(et.next()); + } + }; + + template <> + struct Getter<0> + { + template + static inline size_t get(const ExtType& et) + { + return et.get(); + } + + template + static inline auto getX(const ExtType& et) + -> decltype(et.next()) + { + return et.next(); + } + }; + +} // end namespace XFOR + +/* ========================= * + * --- TEMPLATE CODE --- * + * ========================= */ + +namespace XFOR +{ + + template + inline MExt::MExt(size_t ext, X next) : mExt(ext), mNext(next) {} + + template + template + inline MExt::MExt(const std::array& arr) : + mExt(std::get(arr)), mNext(arr) {} + + template + inline size_t MExt::val() const + { + return mExt; + } + + template + inline const X& MExt::next() const + { + return mNext; + } + + template + inline MExt MExt::operator+(const MExt& in) const + { + return MExt(mExt + in.val(), mNext + in.next()); + } + + template + inline MExt MExt::operator*(size_t in) const + { + return MExt(mExt * in, mNext * in); + } + + + //template <> + inline MExt::MExt(size_t ext) : mExt(ext) {} + + + //template <> + template + inline MExt::MExt(const std::array& arr) : + mExt(std::get(arr)) {} + + //template <> + inline size_t MExt::val() const + { + return mExt; + } + + //template <> + inline MExt MExt::operator+(const MExt& in) const + { + return MExt(mExt + in.val()); + } + + //template <> + inline MExt MExt::operator*(size_t in) const + { + return MExt(mExt * in); + } + + +} // end namespace XFOR + + +#endif diff --git a/src/xfor/for_params.h b/src/xfor/for_params.h deleted file mode 100644 index 5da04b9..0000000 --- a/src/xfor/for_params.h +++ /dev/null @@ -1,63 +0,0 @@ - -#ifndef __for_params_h__ -#define __for_params_h__ - -namespace MultiArrayHelper -{ - - template - class ForParam - { - private: - size_t mVal; - P mNext; - - public: - ForParam(const ForParam& last, const ForParam& ext, size_t pos); - inline const P& next() const; - inline const size_t& val() const; - - }; - - template <> - class ForParam - { - private: - size_t mVal; - - public: - ForParam(const ForParam& last, const ForParam& ext, size_t pos); - inline const size_t& val() const; - }; - - template - ForParam

::ForParam(const ForParam& last, const ForParam& ext, size_t pos) : - mVal(last.val() + pos * ext.val()), mNext(last.next(), ext.next(), pos) {} - - template <> - ForParam::ForParam(const ForParam& last, const ForParam& ext, size_t pos) : - mVal(last.val() + pos * ext.val()) {} - - template - inline const P& ForParam

::next() const - { - return mNext; - } - - template - inline const size_t& ForParam

::val() const - { - return mVal; - } - - template <> - inline const size_t& ForParam::val() const - { - return mVal; - } - - -} // end namespace MultiArrayHelper - - -#endif diff --git a/src/xfor/xfor.h b/src/xfor/xfor.h index af59b1c..41f8faa 100644 --- a/src/xfor/xfor.h +++ b/src/xfor/xfor.h @@ -7,7 +7,7 @@ #include #include "xfor/for_utils.h" #include "xfor/for_type.h" -#include "xfor/for_params.h" +#include "xfor/exttype.h" namespace MultiArrayHelper { @@ -46,29 +46,30 @@ namespace MultiArrayHelper size_t mMax; Expr mExpr; - typedef decltype(mExpr.rootSteps()) FParType; - FParType mExt; + typedef decltype(mExpr.rootSteps()) ExtType; + ExtType mExt; public: - static size_t layer() { return Expr::layer() + 1; } - static const size_t LAYER = Expr::LAYER + 1; - static const size_t SIZE = std::remove_reference::type::SIZE; - + static constexpr size_t LAYER = Expr::LAYER + 1; + static constexpr size_t SIZE = Expr::SIZE; + + For(const For& in) = default; + For& operator=(const For& in) = default; For(For&& in) = default; For& operator=(For&& in) = default; For(const std::shared_ptr& indPtr, - Expr&& expr); + Expr expr); For(const IndexClass* indPtr, - Expr&& expr); + Expr expr); - inline void operator()(size_t mlast, const FParType& last) const; + inline void operator()(size_t mlast, ExtType last) const; inline void operator()(size_t mlast = 0) const; - FParType rootSteps(std::intptr_t iPtrNum = 0) const; + auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType; }; @@ -92,7 +93,7 @@ namespace MultiArrayHelper template For::For(const std::shared_ptr& indPtr, - Expr&& expr) : + Expr expr) : mIndPtr(indPtr.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mExpr(expr), mExt(expr.rootSteps( reinterpret_cast( mIndPtr.get() ))) { @@ -103,7 +104,7 @@ namespace MultiArrayHelper template For::For(const IndexClass* indPtr, - Expr&& expr) : + Expr expr) : mIndPtr(indPtr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mExpr(std::forward( expr )), mExt(expr.rootSteps( reinterpret_cast( mIndPtr ) )) @@ -115,13 +116,11 @@ namespace MultiArrayHelper template inline void For::operator()(size_t mlast, - const FParType& last) const + const ExtType last) const { for(size_t pos = mSPos; pos != mMax; ++pos){ - //const size_t mnpos = mlast * max + pos; const size_t mnpos = PosForward::value(mlast, mMax, pos); - //const FParType npos = std::move( XFPackNum::mkPos(pos, mExt, last) ); - const FParType npos(mlast, mExt, pos); + const ExtType npos = last + mExt*pos; mExpr(mnpos, npos); } } @@ -129,18 +128,17 @@ namespace MultiArrayHelper template inline void For::operator()(size_t mlast) const { - const FParType last; + const ExtType last; for(size_t pos = mSPos; pos != mMax; ++pos){ - //const size_t mnpos = mlast * max + pos; const size_t mnpos = PosForward::value(mlast, mMax, pos); - //const FParType npos = std::move( XFPackNum::mkPos(pos, mExt, last) ); - const FParType npos(mlast, mExt, pos); + const ExtType npos = last + mExt*pos; mExpr(mnpos, npos); } } template - typename For::FParType For::rootSteps(std::intptr_t iPtrNum) const + auto For::rootSteps(std::intptr_t iPtrNum) const + -> ExtType { return mExpr.rootSteps(iPtrNum); }