fix: copying slicecontraction changes instance of internal targte array -> use shared ptr

This commit is contained in:
Christian Zimmermann 2018-09-25 14:06:17 +02:00
parent d13d9f7b72
commit ca01dcaa10

View file

@ -482,14 +482,14 @@ namespace MultiArrayTools
private: private:
const Op& mOp; const Op& mOp;
mutable MultiArray<T,typename Indices::RangeType...> mCont; mutable std::shared_ptr<MultiArray<T,typename Indices::RangeType...> > mCont;
mutable OperationRoot<T,typename Indices::RangeType...> mTarOp; mutable OperationRoot<T,typename Indices::RangeType...> mTarOp;
public: public:
typedef decltype(mOp.rootSteps(0)) ETuple; typedef decltype(mOp.rootSteps(0)) ETuple;
SliceContraction(const Op& op, std::shared_ptr<Indices>... ind); SliceContraction(const Op& op, std::shared_ptr<Indices>... ind);
template <class ET> template <class ET>
inline const value_type& get(ET pos) const; inline const value_type& get(ET pos) const;
@ -1011,8 +1011,9 @@ namespace MultiArrayTools
SliceContraction<T,Op,Indices...>::SliceContraction(const Op& op, SliceContraction<T,Op,Indices...>::SliceContraction(const Op& op,
std::shared_ptr<Indices>... ind) : std::shared_ptr<Indices>... ind) :
mOp(op), mOp(op),
mCont(ind->range()...), mCont(std::make_shared<MultiArray<T,typename Indices::RangeType...> >(ind->range()...)),
mTarOp(mCont,ind...) {} mTarOp(*mCont,ind...)
{ }
// forward loop !!!! // forward loop !!!!
template <typename T, class Op, class... Indices> template <typename T, class Op, class... Indices>
@ -1020,9 +1021,10 @@ namespace MultiArrayTools
inline const MultiArray<T,typename Indices::RangeType...>& inline const MultiArray<T,typename Indices::RangeType...>&
SliceContraction<T,Op,Indices...>::get(ET pos) const SliceContraction<T,Op,Indices...>::get(ET pos) const
{ {
mCont *= 0; // grrr *mCont = 0;
mTarOp = mOp.set(pos); // SET FUNCTION!! mOp.set(pos);
return mCont; mTarOp = mOp;
return *mCont;
} }
template <typename T, class Op, class... Indices> template <typename T, class Op, class... Indices>