diff --git a/src/include/helper_tools.cc.h b/src/include/helper_tools.cc.h index 3e9b4b7..8822929 100644 --- a/src/include/helper_tools.cc.h +++ b/src/include/helper_tools.cc.h @@ -6,7 +6,7 @@ namespace MultiArrayTools template std::ostream& operator<<(std::ostream& out, const std::tuple& tp) { - MA_SFOR(i,0,sizeof...(T)-1,i+1, out << std::get(tp) << ", ";); + sfor_pn<0,sizeof...(T)-1>( [&](auto i){ out << std::get(tp) << ", "; return 0; } ); out << std::get(tp); return out; } @@ -22,8 +22,7 @@ namespace MultiArrayTools auto getIndex() -> std::shared_ptr { - static_assert( RangeType::defaultable, - /*typeid(typename RangeType).name() + */" is not defaultable" ); + static_assert( RangeType::defaultable, "Range not defaultable" ); static auto f = RangeType::factory(); static auto r = std::dynamic_pointer_cast( f.create() ); return std::make_shared(r); diff --git a/src/include/multi_array.cc.h b/src/include/multi_array.cc.h index 592255d..1601be3 100644 --- a/src/include/multi_array.cc.h +++ b/src/include/multi_array.cc.h @@ -206,9 +206,9 @@ namespace MultiArrayTools (*this) = in; } else { - MA_SCFOR2(i,0,sizeof...(SRanges),i+1, - std::get(MAB::mRange->space()).get() == std::get(in.mRange->space()).get(), - operator&&); + sfor_p<0,sizeof...(SRanges),0> + ( [&](auto i) { return std::get(MAB::mRange->space()).get() == std::get(in.mRange->space()).get(); }, + [&](auto a, auto b) { return a and b; }); for(size_t i = 0; i != mCont.size(); ++i){ mCont[i] += in.mCont[i]; } @@ -223,9 +223,9 @@ namespace MultiArrayTools (*this) = in; } else { - MA_SCFOR2(i,0,sizeof...(SRanges),i+1, - std::get(MAB::mRange->space()).get() == std::get(in.mRange->space()).get(), - operator&&); + sfor_p<0,sizeof...(SRanges),0> + ( [&](auto i) { return std::get(MAB::mRange->space()).get() == std::get(in.mRange->space()).get(); }, + [&](auto a, auto b) { return a and b; }); for(size_t i = 0; i != mCont.size(); ++i){ mCont[i] -= in.mCont[i]; } diff --git a/src/include/multi_array_operation.cc.h b/src/include/multi_array_operation.cc.h index dbee69f..7639247 100644 --- a/src/include/multi_array_operation.cc.h +++ b/src/include/multi_array_operation.cc.h @@ -216,7 +216,6 @@ namespace MultiArrayTools template inline DExt AssignmentExpr::dExtension() const { - CHECK; return nullptr; //???!!! } @@ -243,7 +242,10 @@ namespace MultiArrayTools template auto MOp::loop(Expr exp) const { - return MA_SCRAFOR(i,sizeof...(Ops),0,i-1,std::get(mOps.mOps),loop,exp); + return sfor_m + ( [&](auto i){ return std::get(mOps.mOps); }, + [&](auto f, auto next) { return f.loop(next); }, + exp ); } template @@ -331,7 +333,6 @@ namespace MultiArrayTools { mIndex(indices...); mDataPtr = mOrigDataPtr + mIndex.pos(); - //mOff = mIndex.pos(); } template @@ -342,21 +343,19 @@ namespace MultiArrayTools mIndex( ind ) { mDataPtr = mOrigDataPtr + mIndex.pos(); - //mOff = mIndex.pos(); } template template inline const T& ConstOperationRoot::get(ET pos) const { - return mDataPtr[pos.val()/*+mOff*/]; + return mDataPtr[pos.val()]; } template template inline const V& ConstOperationRoot::vget(ET pos) const { - //VCHECK(pos.val()); return *(reinterpret_cast(mDataPtr+pos.val())); } @@ -364,8 +363,6 @@ namespace MultiArrayTools template inline ConstOperationRoot& ConstOperationRoot::set(ET pos) { - //mIndex = pos.val(); - //mDataPtr = mOrigDataPtr + mIndex.pos(); mDataPtr = mOrigDataPtr + pos.val(); return *this; } @@ -373,8 +370,6 @@ namespace MultiArrayTools template const T* ConstOperationRoot::data() const { - //auto i = mIndex; - //return mOrigDataPtr/* + i().pos()*/; return mDataPtr; } @@ -452,9 +447,6 @@ namespace MultiArrayTools inline typename MetaOperationRoot::value_type MetaOperationRoot::get(ET pos) const { - //VCHECK(pos.val()); - //VCHECK(mDataPtr); - //VCHECK(mDataPtr[pos.val()]) return (mWorkIndex = pos.val()).meta(); } @@ -471,7 +463,6 @@ namespace MultiArrayTools template inline MetaOperationRoot& MetaOperationRoot::set(ET pos) { - //(*mIndex) = pos.val(); return *this; } @@ -646,7 +637,6 @@ namespace MultiArrayTools OperationRoot& OperationRoot::operator+=(const OpClass& in) { VExec::template exec(*this,in); - //plus(in)(); return *this; } @@ -673,7 +663,6 @@ namespace MultiArrayTools template inline V& OperationRoot::vget(ET pos) const { - //VCHECK(pos.val()); return *(reinterpret_cast(mDataPtr+pos.val())); } @@ -681,8 +670,6 @@ namespace MultiArrayTools template inline OperationRoot& OperationRoot::set(ET pos) { - //mIndex = pos.val(); - //mDataPtr = mOrigDataPtr + mIndex.pos(); mDataPtr = mOrigDataPtr + pos.val(); return *this; } @@ -703,8 +690,6 @@ namespace MultiArrayTools template T* OperationRoot::data() const { - //auto i = mIndex; - //return mOrigDataPtr/* + i().pos()*/; return mDataPtr; } @@ -1063,7 +1048,10 @@ namespace MultiArrayTools template auto Operation::loop(Expr exp) const { - return MA_SCRAFOR(i,sizeof...(Ops),0,i-1,std::get(mOps.mOps),loop,exp); + return sfor_m + ( [&](auto i){ return std::get(mOps.mOps); }, + [&](auto f, auto next) { return f.loop(next); }, + exp ); } diff --git a/src/include/multi_array_operation.h b/src/include/multi_array_operation.h index f3e32b2..18e67e4 100644 --- a/src/include/multi_array_operation.h +++ b/src/include/multi_array_operation.h @@ -310,7 +310,9 @@ namespace MultiArrayTools template auto OperationTuple::rootSteps(std::intptr_t iPtrNum) const { - return MA_SCFOR(i,0,sizeof...(Ops),i+1,std::get(mOps).rootSteps(iPtrNum),extend); + return sfor_p<0,sizeof...(Ops)> + ( [&](auto i){ return std::get(mOps).rootSteps(iPtrNum); }, + [&](auto f, auto next) { return f.extend(next); } ); } template @@ -778,42 +780,6 @@ namespace MultiArrayTools T const** data() const { assert(0); return nullptr; } }; - /* - template - struct TFold - { - TFold() = default; - TFold(const TFold& in) = default; - TFold& operator=(const TFold& in) = default; - TFold(TFold&& in) = default; - TFold& operator=(TFold&& in) = default; - explicit TFold(const T v) : val(v) {} - - T val; - inline T& operator*() { return val; } - inline const T& operator*() const { return val; } - }; - - template - inline std::tuple,TFold> operator,(const TFold& a1, const TFold& a2) - { - return std::make_tuple(a1,a2); - } - - template - inline std::tuple,TFold> operator,(const TFold& a1, - const std::tuple...>& a2) - { - return std::tuple_cat(std::make_tuple(a1),a2); - } - - template - inline std::tuple,TFold> operator,(const std::tuple...>& a1, - const TFold& a2) - { - return std::tuple_cat(a1,std::make_tuple(a2)); - } - */ template class Operation : public OperationTemplate > { diff --git a/src/include/slice.cc.h b/src/include/slice.cc.h index 0505805..54235c3 100644 --- a/src/include/slice.cc.h +++ b/src/include/slice.cc.h @@ -243,9 +243,12 @@ namespace MultiArrayTools SliceDef& SliceDef::operator=(const OperationRoot& op) { std::array blocks; - MA_SFOR(i,0,sizeof...(SRanges),i+1, - std::get(blocks) = op.rootSteps(reinterpret_cast - ( mIndex.template getPtr().get())).val();); + sfor_pn<0,sizeof...(SRanges)> + ( [&](auto i) { + std::get(blocks) = + op.rootSteps(reinterpret_cast + ( mIndex.template getPtr().get())).val(); + return 0; } ); mSl.format(blocks); mSl.mData = op.data(); return *this; @@ -265,9 +268,12 @@ namespace MultiArrayTools ConstSliceDef& ConstSliceDef::operator=(const ConstOperationRoot& op) { std::array blocks; - MA_SFOR(i,0,sizeof...(SRanges),i+1, - std::get(blocks) = op.rootSteps(reinterpret_cast - ( mIndex.template getPtr().get())).val();); + sfor_pn<0,sizeof...(SRanges)> + ( [&](auto i) { + std::get(blocks) = + op.rootSteps(reinterpret_cast + ( mIndex.template getPtr().get())).val(); + return 0; } ); mSl.format(blocks); mSl.mData = op.data(); return *this; @@ -278,9 +284,12 @@ namespace MultiArrayTools ConstSliceDef& ConstSliceDef::operator=(const OperationRoot& op) { std::array blocks; - MA_SFOR(i,0,sizeof...(SRanges),i+1, - std::get(blocks) = op.rootSteps(reinterpret_cast - ( mIndex.template getPtr().get())).val();); + sfor_pn<0,sizeof...(SRanges)> + ( [&](auto i) { + std::get(blocks) = + op.rootSteps(reinterpret_cast + ( mIndex.template getPtr().get())).val(); + return 0; } ); mSl.format(blocks); mSl.mData = op.data(); return *this; diff --git a/src/include/slice.h b/src/include/slice.h index 70c1af3..ab7d196 100644 --- a/src/include/slice.h +++ b/src/include/slice.h @@ -112,9 +112,12 @@ namespace MultiArrayTools { Slice out(ind->range()->space(), &*ind); std::array ff; - MA_SFOR(i,0,sizeof...(SRanges),i+1, - std::get(ff) = op.rootSteps(reinterpret_cast - ( ind.template getPtr().get())).val();); + sfor_pn<0,sizeof...(SRanges)> + ( [&](auto i) { + std::get(ff) = + op.rootSteps(reinterpret_cast + ( ind.template getPtr().get())).val(); + return 0; } ); out.format(ff); return out; } @@ -145,9 +148,12 @@ namespace MultiArrayTools { ConstSlice out(ind->range()->space(), &*ind); std::array ff; - MA_SFOR(i,0,sizeof...(SRanges),i+1, - std::get(ff) = op.rootSteps(reinterpret_cast - ( ind.template getPtr().get())).val();); + sfor_pn<0,sizeof...(SRanges)> + ( [&](auto i) { + std::get(ff) = + op.rootSteps(reinterpret_cast + ( ind.template getPtr().get())).val(); + return 0; } ); out.format(ff); return out; } diff --git a/src/include/statics/static_for.h b/src/include/statics/static_for.h index 77d393a..5c43d27 100644 --- a/src/include/statics/static_for.h +++ b/src/include/statics/static_for.h @@ -169,15 +169,4 @@ namespace MultiArrayTools } -#define MA_SFOR(i,beg,end,incr,expr) sfor([&](auto i) constexpr { return incr; }, [&](auto i){ expr return 0; }, [&](auto f, auto next) { return 0; }) -#define MA_SCFOR(i,beg,end,incr,expr,conc) sfor([&](auto i) constexpr { return incr; }, [&](auto i){ return expr; }, [&](auto f, auto next) { return f.conc(next); }) -#define MA_SCFOR2(i,beg,end,incr,expr,conc) sfor([&](auto i) constexpr { return incr; }, [&](auto i){ return expr; }, [&](auto a, auto b) { return conc(a,b); }) -#define MA_SCFOR3(i,beg,end,incr,expr,conc) sfor([&](auto i) constexpr { return incr; }, [&](auto i){ return expr; }, conc) -#define MA_SRFOR(i,beg,end,decr,expr) sfor([&](auto i) constexpr { return decr; }, [&](auto i){ expr return 0; }, [&](auto f, auto next) { return 0; }) -#define MA_SCRFOR(i,beg,end,decr,expr,conc) sfor([&](auto i) constexpr { return decr; }, [&](auto i){ return expr; }, [&](auto f, auto next) { return f.conc(next); }) -#define MA_SCRAFOR(i,beg,end,decr,expr,conc,arg) sfor([&](auto i) constexpr { return decr; }, [&](auto i){ return expr; }, [&](auto f, auto next) { return f.conc(next); }, arg) -#define MA_CFOR(i,beg,end,incr,expr,cre) unpack([&](auto i) constexpr { return incr; }, [&](auto i){ expr }, [&](auto... args) { return cre(args...); }) - -#define MA_SCFOR_X(i,beg,end,incr,expr,conc) sfor([](auto i) constexpr { return incr; }, [](auto i){ return expr; }, [](auto f, auto next) { return f.conc(next); }) - #endif diff --git a/src/include/type_operations.h b/src/include/type_operations.h index 3e13521..be955d1 100644 --- a/src/include/type_operations.h +++ b/src/include/type_operations.h @@ -33,7 +33,10 @@ namespace MultiArrayTools inline auto apply(const MultiArray& ma) -> OperationRoot { - return MA_CFOR(i,0,sizeof...(Ranges),i+1,return std::get(ituple);,ma); + return unpack<0,sizeof...(Ranges),0> + ( [&](auto i) constexpr { return i+1; }, + [&](auto i){ return std::get(ituple); }, + [&](auto... args) { return ma(args...); }); } private: