diff --git a/src/include/multi_array.h b/src/include/multi_array.h index 63a2309..6ab76db 100644 --- a/src/include/multi_array.h +++ b/src/include/multi_array.h @@ -56,8 +56,8 @@ namespace MultiArrayTools //template //MultiArray& operator=(const MultiArray,Range3> in); - virtual T& operator[](const IndexType& i) override; - virtual const T& operator[](const IndexType& i) const override; + virtual T& operator[](const IndexType& i) final; + virtual const T& operator[](const IndexType& i) const final; virtual T& at(const typename IndexType::MetaType& meta) override; virtual const T& at(const typename IndexType::MetaType& meta) const override; diff --git a/src/include/multi_array_base.h b/src/include/multi_array_base.h index 73312f7..a01343d 100644 --- a/src/include/multi_array_base.h +++ b/src/include/multi_array_base.h @@ -39,6 +39,9 @@ namespace MultiArrayTools virtual ~MultiArrayBase() = default; + template + const T& operator[](const ContainerIndex& i); + virtual const T& operator[](const IndexType& i) const = 0; virtual const T& at(const typename CRange::IndexType::MetaType& meta) const = 0; @@ -95,6 +98,9 @@ namespace MultiArrayTools DEFAULT_MEMBERS(MutableMultiArrayBase); MutableMultiArrayBase(const std::shared_ptr&... ranges); MutableMultiArrayBase(const typename CRange::Space& space); + + template + T& operator[](const ContainerIndex& i); virtual T& operator[](const IndexType& i) = 0; virtual T& at(const typename CRange::IndexType::MetaType& meta) = 0; @@ -158,6 +164,16 @@ namespace MultiArrayTools mRange = std::dynamic_pointer_cast >( crf.create() ); mProtoI = std::make_shared( mRange, reinterpret_cast(this) ); } + + template + template + const T& MultiArrayBase::operator[](const ContainerIndex& i) + { + IndexType ii(*mProtoI); + ii = i; + return (*this)[ii]; + } + template size_t MultiArrayBase::size() const @@ -279,6 +295,17 @@ namespace MultiArrayTools return i.setData(data()); } */ + + template + template + T& MutableMultiArrayBase::operator[](const ContainerIndex& i) + { + IndexType ii(*MAB::mProtoI); + ii = i; + return (*this)[ii]; + } + + template bool MutableMultiArrayBase::isConst() const { diff --git a/src/include/ranges/container_range.h b/src/include/ranges/container_range.h index 6ab5a8f..090d873 100644 --- a/src/include/ranges/container_range.h +++ b/src/include/ranges/container_range.h @@ -33,6 +33,12 @@ namespace MultiArrayTools static constexpr size_t totalDim() { return mkTotalDim(); } static constexpr SpaceType STYPE = SpaceType::ANY; + + template + using CIX = ContainerIndex; + + template + friend class CIX; private: @@ -50,6 +56,9 @@ namespace MultiArrayTools ContainerIndex(const ContainerIndex& in) = default; ContainerIndex& operator=(const ContainerIndex& in) = default; + + template + ContainerIndex& operator=(const ContainerIndex& in); template ContainerIndex(const std::shared_ptr& range, @@ -251,7 +260,16 @@ namespace MultiArrayTools IB::mPos = RPackNum::makePos(mIPack, mBlockSizes); mNonTrivialBlocks = true; } - + + template + template + ContainerIndex& + ContainerIndex::operator=(const ContainerIndex& in) + { + mIPack = in.mIPack; + return (*this)(); + } + template ContainerIndex& ContainerIndex::sync() diff --git a/src/include/slice.h b/src/include/slice.h index 12e4ee5..2937fa4 100644 --- a/src/include/slice.h +++ b/src/include/slice.h @@ -23,7 +23,7 @@ namespace MultiArrayTools ConstSlice(const std::shared_ptr&... ranges, const T* data = nullptr); ConstSlice(const MultiArrayBase& ma, SIZET... sizes); - virtual const T& operator[](const IType& i) const override; + virtual const T& operator[](const IType& i) const final; virtual const T& at(const typename IType::MetaType& meta) const override; virtual const T* data() const override; @@ -63,8 +63,8 @@ namespace MultiArrayTools Slice(const std::shared_ptr&... ranges, T* data = nullptr); - virtual const T& operator[](const IType& i) const override; - virtual T& operator[](const IType& i) override; + virtual const T& operator[](const IType& i) const final; + virtual T& operator[](const IType& i) final; virtual const T& at(const typename IType::MetaType& meta) const override; virtual T& at(const typename IType::MetaType& meta) override;