diff --git a/src/include/map_range.cc.h b/src/include/map_range.cc.h index 87f8076..fcb2a49 100644 --- a/src/include/map_range.cc.h +++ b/src/include/map_range.cc.h @@ -591,7 +591,7 @@ namespace MultiArrayTools vector GenMapRange::typeNum() const { vector o; - RPackNum::getTypeNum(o,mSpace); + RangeHelper::getTypeNum(o,mSpace); return o; } diff --git a/src/include/ranges/anonymous_range.h b/src/include/ranges/anonymous_range.h index f8ee5b9..48a5a00 100644 --- a/src/include/ranges/anonymous_range.h +++ b/src/include/ranges/anonymous_range.h @@ -213,7 +213,9 @@ namespace MultiArrayTools RangeInterface() { RPackNum::RangesToVec( origs, mOrig ); - mSize = RPackNum::getSize( origs ); + mSize = sfor_p<0,sizeof...(RangeTypes)> + ( [&](auto i) { return std::get(origs)->size(); }, + [&](auto a, auto b) { return a * b; } ); if(sizeof...(RangeTypes)){ mEmpty = false; } @@ -225,7 +227,9 @@ namespace MultiArrayTools { auto rst = std::make_tuple(origs...); RPackNum::RangesToVec( rst, mOrig ); - mSize = RPackNum::getSize( rst ); + mSize = sfor_p<0,sizeof...(RangeTypes)> + ( [&](auto i) { return std::get(rst)->size(); }, + [&](auto a, auto b) { return a * b; } ); if(sizeof...(RangeTypes)){ mEmpty = false; } diff --git a/src/include/ranges/dynamic_range.cc.h b/src/include/ranges/dynamic_range.cc.h index de305cd..e5ae01f 100644 --- a/src/include/ranges/dynamic_range.cc.h +++ b/src/include/ranges/dynamic_range.cc.h @@ -144,7 +144,9 @@ namespace MultiArrayTools RangeInterface() { RPackNum::RangesToVec( origs, mOrig ); - mSize = RPackNum::getSize( origs ); + mSize = sfor_p<0,sizeof...(RangeTypes)> + ( [&](auto i) { return std::get(origs)->size(); }, + [&](auto a, auto b) { return a * b; } ); if(sizeof...(RangeTypes)){ mEmpty = false; } @@ -157,7 +159,9 @@ namespace MultiArrayTools { auto rst = std::make_tuple(origs...); RPackNum::RangesToVec( rst, mOrig ); - mSize = RPackNum::getSize( rst ); + mSize = sfor_p<0,sizeof...(RangeTypes)> + ( [&](auto i) { return std::get(rst)->size(); }, + [&](auto a, auto b) { return a * b; } ); if(sizeof...(RangeTypes)){ mEmpty = false; } diff --git a/src/include/ranges/multi_range.h b/src/include/ranges/multi_range.h index 02a4cfe..33e45d8 100644 --- a/src/include/ranges/multi_range.h +++ b/src/include/ranges/multi_range.h @@ -564,7 +564,7 @@ namespace MultiArrayTools template size_t MultiRange::getMeta(const MetaType& metaPos) const { - return RPackNum::getMeta(mSpace,metaPos); + return RangeHelper::getMeta(mSpace,metaPos); } template @@ -593,7 +593,10 @@ namespace MultiArrayTools template size_t MultiRange::size() const { - return RPackNum::getSize(mSpace); + return sfor_p<0,sizeof...(Ranges)> + ( [&](auto i) { return std::get(mSpace)->size(); }, + [&](auto a, auto b) { return a * b; } ); + //return RPackNum::getSize(mSpace); } template @@ -612,7 +615,7 @@ namespace MultiArrayTools vector MultiRange::typeNum() const { vector o; - RPackNum::getTypeNum(o,mSpace); + RangeHelper::getTypeNum(o,mSpace); return o; } diff --git a/src/include/ranges/range_helper.h b/src/include/ranges/range_helper.h index 88d2c3a..164cb16 100644 --- a/src/include/ranges/range_helper.h +++ b/src/include/ranges/range_helper.h @@ -16,6 +16,30 @@ namespace MultiArrayTools setIndexPack(iPack, (pos - ownPos) / i.max() ); } } + + template + inline size_t getMeta(const std::tuple...>& space, + const std::tuple& meta) + { + if constexpr(N != 0){ + return getMeta(space,meta) * std::get(space)->size() + + std::get(space)->getMeta(std::get(meta)); + } + else { + return std::get<0>(space)->getMeta(std::get<0>(meta)); + } + } + + template + inline void getTypeNum(vector& res, const std::tuple...>& stp) + { + auto& r = *std::get(stp); + auto tn = r.typeNum(); + res.insert(res.begin(), tn.begin(), tn.end()); + if constexpr(N != 0){ + getTypeNum(res, stp); + } + } } // namespace RangeHelper } // namespace MultiArrayTools diff --git a/src/include/ranges/rpack_num.cc.h b/src/include/ranges/rpack_num.cc.h index 600943c..4c474c9 100644 --- a/src/include/ranges/rpack_num.cc.h +++ b/src/include/ranges/rpack_num.cc.h @@ -33,13 +33,6 @@ namespace MultiArrayHelper v.insert(v.begin(), r); } - template - template - size_t RPackNum::getSize(const RangeTuple& rt) - { - return std::get(rt)->size() * RPackNum::getSize(rt); - } - template template inline size_t RPackNum::makePos(const std::tuple...>& iPtrTup, @@ -215,33 +208,7 @@ namespace MultiArrayHelper return r.cmetaSize() + RPackNum::getCMetaSize(stp); } - template - template - inline void RPackNum::getTypeNum(vector& res, const std::tuple...>& stp) - { - auto& r = *std::get(stp); - auto tn = r.typeNum(); - res.insert(res.begin(), tn.begin(), tn.end()); - RPackNum::getTypeNum(res, stp); - } - template - template - inline size_t RPackNum::getMeta(const std::tuple...>& space, - const std::tuple& meta) - { - return RPackNum::getMeta(space,meta) * std::get(space)->size() + - std::get(space)->getMeta(std::get(meta)); - } - - - - template - size_t RPackNum<0>::getSize(const RangeTuple& rt) - { - return std::get<0>(rt)->size(); - } - template inline size_t RPackNum<0>::makePos(const std::tuple...>& iPtrTup, const std::array& blockSize) @@ -388,20 +355,6 @@ namespace MultiArrayHelper return r.cmetaSize(); } - template - inline void RPackNum<0>::getTypeNum(vector& res, const std::tuple...>& stp) - { - auto& r = *std::get<0>(stp); - auto tn = r.typeNum(); - res.insert(res.begin(), tn.begin(), tn.end()); - } - - template - inline size_t RPackNum<0>::getMeta(const std::tuple...>& space, - const std::tuple& meta) - { - return std::get<0>(space)->getMeta(std::get<0>(meta)); - } template diff --git a/src/include/ranges/rpack_num.h b/src/include/ranges/rpack_num.h index 4ef41ef..3459c3b 100644 --- a/src/include/ranges/rpack_num.h +++ b/src/include/ranges/rpack_num.h @@ -102,9 +102,6 @@ namespace MultiArrayHelper struct RPackNum { - template - static size_t getSize(const RangeTuple& rt); - template static inline size_t makePos(const std::tuple...>& iPtrTup, const std::array& blockSize); @@ -175,12 +172,6 @@ namespace MultiArrayHelper template static inline size_t getCMetaSize(const std::tuple...>& stp); - template - static inline void getTypeNum(vector& res, const std::tuple...>& stp); - - template - static inline size_t getMeta(const std::tuple...>& space, - const std::tuple& meta); }; @@ -188,9 +179,6 @@ namespace MultiArrayHelper struct RPackNum<0> { - template - static size_t getSize(const RangeTuple& rt); - template static inline size_t makePos(const std::tuple...>& iPtrTup, const std::array& blockSize); @@ -259,12 +247,6 @@ namespace MultiArrayHelper template static inline size_t getCMetaSize(const std::tuple...>& stp); - template - static inline void getTypeNum(vector& res, const std::tuple...>& stp); - - template - static inline size_t getMeta(const std::tuple...>& space, - const std::tuple& meta); }; template diff --git a/src/include/xfor/exttype.h b/src/include/xfor/exttype.h index 50b2229..9dd7c07 100644 --- a/src/include/xfor/exttype.h +++ b/src/include/xfor/exttype.h @@ -258,7 +258,7 @@ namespace MultiArrayHelper class DExtTX { private: - mutable DExt mDExt = nullptr; + mutable DExt mDExt; X mNext; template @@ -268,7 +268,8 @@ namespace MultiArrayHelper static constexpr size_t SIZE = NUM + 1; DExtTX() { mDExt = std::make_shared>(); } - DExtTX(const DExtTX& in) : mDExt(in.mDExt->deepCopy()), mNext(in.mNext) {} + DExtTX(const DExtTX& in) : mNext(in.mNext) + { mDExt = in.mDExt->deepCopy(); } DExtTX(DExtTX&& in) : mDExt(in.mDExt->deepCopy()), mNext(in.mNext) {} DExtTX& operator=(const DExtTX& in) { mNext = in.mNext; mDExt = in.mDExt->deepCopy(); return *this; } DExtTX& operator=(DExtTX&& in) { mNext = in.mNext; mDExt = in.mDExt->deepCopy(); return *this; }