diff --git a/src/include/multi_array_operation.h b/src/include/multi_array_operation.h index 6a9f3bc..6eb82b8 100644 --- a/src/include/multi_array_operation.h +++ b/src/include/multi_array_operation.h @@ -248,6 +248,7 @@ namespace MultiArrayTools typedef decltype(PackNum::template mkSteps(0, mOps)) ETuple; Operation(const Ops&... ops); + Operation(std::shared_ptr ff, const Ops&... ops); template inline T get(ET pos) const; @@ -522,7 +523,19 @@ namespace MultiArrayTools template Operation::Operation(const Ops&... ops) : - mOps(ops...) {} + mOps(ops...) + { + static_assert( FISSTATIC, "need function instance for non-static function" ); + } + + template + Operation::Operation(std::shared_ptr ff, + const Ops&... ops) : + mOps(ops...), + mF(ff) + { + static_assert( not FISSTATIC, "using instance of function supposed to be static" ); + } template template @@ -530,7 +543,7 @@ namespace MultiArrayTools { typedef std::tuple OpTuple; return PackNum:: - template mkOpExpr(pos, mOps); + template mkOpExpr(mF, pos, mOps); } template diff --git a/src/include/pack_num.h b/src/include/pack_num.h index b0b968a..f197c6e 100644 --- a/src/include/pack_num.h +++ b/src/include/pack_num.h @@ -13,6 +13,26 @@ namespace MultiArrayHelper { + template + struct Application + { + template + static inline T apply(std::shared_ptr f, T a, Ts... as) + { + return (*f)(a, as...); + } + }; + + template <> + struct Application + { + template + static inline T apply(std::shared_ptr f, T a, Ts... as) + { + return OpFunction::apply(a, as...); + } + }; + template struct PackNum @@ -41,13 +61,13 @@ namespace MultiArrayHelper } template - static inline T mkOpExpr(const ETuple& pos, const OpTuple& ops, const Args&... args) + static inline T mkOpExpr(std::shared_ptr f, const ETuple& pos, const OpTuple& ops, const Args&... args) { typedef typename std::remove_reference(ops))>::type NextOpType; static_assert(LAST > NextOpType::SIZE, "inconsistent array positions"); static constexpr size_t NEXT = LAST - NextOpType::SIZE; return PackNum::template mkOpExpr - ( pos, ops, std::get(ops).get(Getter::template getX( pos )), args...); + ( f, pos, ops, std::get(ops).get(Getter::template getX( pos )), args...); } template @@ -94,14 +114,15 @@ namespace MultiArrayHelper { std::get<0>(out) = second.rootSteps( std::get<0>(siar) ); } - + template - static inline T mkOpExpr(const ETuple& pos, const OpTuple& ops, const Args&... args) + static inline T mkOpExpr(std::shared_ptr f, const ETuple& pos, const OpTuple& ops, const Args&... args) { typedef typename std::remove_reference(ops))>::type NextOpType; static constexpr size_t NEXT = LAST - NextOpType::SIZE; static_assert(NEXT == 0, "inconsistent array positions"); - return OpFunction::apply(std::get<0>(ops).get(Getter<0>::template getX( pos )), args...); + return Application::apply(f, std::get<0>(ops).get(Getter<0>::template getX( pos )), args...); + //return OpFunction::apply(std::get<0>(ops).get(Getter<0>::template getX( pos )), args...); } template diff --git a/src/include/ranges/anonymous_range.h b/src/include/ranges/anonymous_range.h index c22f6dd..d47999c 100644 --- a/src/include/ranges/anonymous_range.h +++ b/src/include/ranges/anonymous_range.h @@ -51,7 +51,12 @@ namespace MultiArrayTools virtual IndexType begin() const override; virtual IndexType end() const override; - + + std::shared_ptr sub(size_t num) const; + + template + std::shared_ptr fullsub(size_t num) const; + friend AnonymousRangeFactory; protected: @@ -118,6 +123,12 @@ namespace MultiArrayTools //RPackNum::getSize( rst ); } + template + std::shared_ptr AnonymousRange::fullsub(size_t num) const + { + return std::dynamic_pointer_cast( mOrig.at(num) ); + } + /***************** * Functions * *****************/ diff --git a/src/lib/ranges/anonymous_range.cc b/src/lib/ranges/anonymous_range.cc index a302dc1..61271dc 100644 --- a/src/lib/ranges/anonymous_range.cc +++ b/src/lib/ranges/anonymous_range.cc @@ -54,6 +54,11 @@ namespace MultiArrayTools i = size(); return i; } + + std::shared_ptr AnonymousRange::sub(size_t num) const + { + return mOrig.at(num); + } /***************** * Functions *