indices: fullfill missing iterator requirements

This commit is contained in:
Christian Zimmermann 2023-06-11 22:28:10 +02:00
parent 811e955491
commit 1919d373df
15 changed files with 140 additions and 88 deletions

View file

@ -32,6 +32,12 @@
#define SP_DEFAULT_MEMBERS_X(__spec__,__class_name__) SP_DEFAULT_COPY(__spec__,__class_name__); SP_DEFAULT_MOVE(__spec__,__class_name__) #define SP_DEFAULT_MEMBERS_X(__spec__,__class_name__) SP_DEFAULT_COPY(__spec__,__class_name__); SP_DEFAULT_MOVE(__spec__,__class_name__)
#define SP_DEFAULT_MEMBERS(__spec__,__class_name__) SP_DEFAULT_C(__spec__,__class_name__); SP_DEFAULT_MEMBERS_X(__spec__,__class_name__) #define SP_DEFAULT_MEMBERS(__spec__,__class_name__) SP_DEFAULT_C(__spec__,__class_name__); SP_DEFAULT_MEMBERS_X(__spec__,__class_name__)
#define INDEX_RANDOM_ACCESS_ITERATOR_DEFS(__meta_type__) typedef std::random_access_iterator_tag iterator_category; \
typedef SizeT difference_type; \
typedef __meta_type__ value_type; \
typedef const __meta_type__* pointer; \
typedef const __meta_type__& reference
#define CXZ_CVAL_FALSE static constexpr bool value = false #define CXZ_CVAL_FALSE static constexpr bool value = false
#define CXZ_CVAL_TRUE static constexpr bool value = true #define CXZ_CVAL_TRUE static constexpr bool value = true

View file

@ -17,6 +17,8 @@ namespace CNORXZ
typedef CRange RangeType; typedef CRange RangeType;
typedef SizeT MetaType; typedef SizeT MetaType;
INDEX_RANDOM_ACCESS_ITERATOR_DEFS(MetaType);
DEFAULT_MEMBERS(CIndex);
CIndex(const RangePtr& range, SizeT pos = 0); CIndex(const RangePtr& range, SizeT pos = 0);
CIndex& operator=(SizeT lexpos); CIndex& operator=(SizeT lexpos);

View file

@ -22,7 +22,7 @@ namespace CNORXZ
return EFor<S,L,Xpr>(mLI->id(), xpr, std::forward<F>(f)); return EFor<S,L,Xpr>(mLI->id(), xpr, std::forward<F>(f));
} }
template <typename MetaType, SizeT S, SizeT L, class I1> template <typename MetaT, SizeT S, SizeT L, class I1>
decltype(auto) operator*(const Sptr<EIndex<MetaT,S,L>>& a, const Sptr<I1>& b) decltype(auto) operator*(const Sptr<EIndex<MetaT,S,L>>& a, const Sptr<I1>& b)
{ {
return iptrMul(a, b); return iptrMul(a, b);
@ -31,16 +31,16 @@ namespace CNORXZ
template <typename MetaT, SizeT S, SizeT L> template <typename MetaT, SizeT S, SizeT L>
decltype(auto) eindexPtr(const Sptr<LIndex<SIndex<MetaT,S>,L>>& i) decltype(auto) eindexPtr(const Sptr<LIndex<SIndex<MetaT,S>,L>>& i)
{ {
return std::make_shared<EIndex<MetaT,S>>(i); return std::make_shared<EIndex<MetaT,S,L>>(i);
} }
template <SizeT L, typename MetaType, SizeT S> template <SizeT L, typename MetaT, SizeT S>
decltype(auto) eindexPtr(const Sptr<SIndex<MetaT,S>>& i) decltype(auto) eindexPtr(const Sptr<SIndex<MetaT,S>>& i)
{ {
return eindexPtr( lindexPtr<L>( i ) ); return eindexPtr( lindexPtr<L>( i ) );
} }
template <typename MetaType, SizeT S, SizeT L> template <typename MetaT, SizeT S, SizeT L>
decltype(auto) eindexPtr(const Sptr<SIndex<MetaT,S>>& i, CSizeT<L> l) decltype(auto) eindexPtr(const Sptr<SIndex<MetaT,S>>& i, CSizeT<L> l)
{ {
return eindexPtr<l>( i ); return eindexPtr<l>( i );
@ -49,16 +49,19 @@ namespace CNORXZ
template <SizeT S, SizeT L1, SizeT L2, class Index> template <SizeT S, SizeT L1, SizeT L2, class Index>
decltype(auto) eplex(const Sptr<Index>& i) decltype(auto) eplex(const Sptr<Index>& i)
{ {
const SizeT isize = i->lmax().val() const SizeT isize = i->lmax().val();
CXZ_ASSERT(isize % S == 0, "index max (= " << isize CXZ_ASSERT(isize % S == 0, "index max (= " << isize
<< " ) not dividable by extension size = " << S); << " ) not dividable by extension size = " << S);
auto ci = std::make_shared<CIndex>( CRangeFactory(isize/L).create() ); auto ci = std::make_shared<CIndex>( CRangeFactory(isize/S).create() );
auto ei = eindexPtr<L1>( std::make_shared<SIndex<S>>( SRangeFactory<S>().create() ) ); auto m = iter<0,S>([](auto i) { return i; },
[](const auto&... e) { return Arr<SizeT,S>{ e... }; } );
auto ei = eindexPtr<L1>( std::make_shared<SIndex<SizeT,S>>
( SRangeFactory<SizeT,S>(m).create() ) );
if constexpr(L2 == 0){ if constexpr(L2 == 0){
return spackp(ci,ei); return spackp(ci,ei);
} }
else { else {
return spackp(lindex<L2>(ci),ei); return spackp(lindexPtr<L2>(ci),ei);
} }
} }

View file

@ -18,8 +18,7 @@ namespace CNORXZ
typedef typename LIndex<SIndex<MetaT,S>,L>::RangeType RangeType; typedef typename LIndex<SIndex<MetaT,S>,L>::RangeType RangeType;
DEFAULT_MEMBERS(EIndex); DEFAULT_MEMBERS(EIndex);
EIndex(const LIndex<SIndex<MetaT,S>,L>& i); EIndex(const Sptr<LIndex<SIndex<MetaT,S>,L>>& i);
EIndex(LIndex<SIndex<MetaT,S>,L>&& i);
template <class Xpr, class F> template <class Xpr, class F>
decltype(auto) ifor(const Xpr& xpr, F&& f) const; decltype(auto) ifor(const Xpr& xpr, F&& f) const;
@ -28,16 +27,22 @@ namespace CNORXZ
Sptr<LIndex<SIndex<MetaT,S>,L>> mLI; Sptr<LIndex<SIndex<MetaT,S>,L>> mLI;
}; };
template <typename MetaType, SizeT S, SizeT L, class I1> template <typename MetaT, SizeT S, SizeT L>
decltype(auto) operator*(const Sptr<EIndex<MetaType,S>>& a, const Sptr<I1>& b); struct is_index<EIndex<MetaT,S,L>>
{
static constexpr bool value = true;
};
template <typename MetaT, SizeT S, SizeT L, class I1>
decltype(auto) operator*(const Sptr<EIndex<MetaT,S,L>>& a, const Sptr<I1>& b);
template <typename MetaType, SizeT S, SizeT L> template <typename MetaT, SizeT S, SizeT L>
decltype(auto) eindexPtr(const Sptr<LIndex<SIndex<MetaT,S>,L>>& i); decltype(auto) eindexPtr(const Sptr<LIndex<SIndex<MetaT,S>,L>>& i);
template <SizeT L, typename MetaType, SizeT S> template <SizeT L, typename MetaT, SizeT S>
decltype(auto) eindexPtr(const Sptr<SIndex<MetaT,S>>& i); decltype(auto) eindexPtr(const Sptr<SIndex<MetaT,S>>& i);
template <typename MetaType, SizeT S, SizeT L> template <typename MetaT, SizeT S, SizeT L>
decltype(auto) eindexPtr(const Sptr<SIndex<MetaT,S>>& i, CSizeT<L> l); decltype(auto) eindexPtr(const Sptr<SIndex<MetaT,S>>& i, CSizeT<L> l);
template <SizeT S, SizeT L1, SizeT L2, class Index> template <SizeT S, SizeT L1, SizeT L2, class Index>

View file

@ -68,10 +68,10 @@ namespace CNORXZ
template <class FormatT> template <class FormatT>
constexpr GMFormat<PosT...>::GMFormat(const FormatT& f) constexpr GMFormat<PosT...>::GMFormat(const FormatT& f)
{ {
static_assert(f.size() == size(), "try to assign format of wrong dimension"); CXZ_ASSERT(f.size() == size(), "try to assign format of wrong dimension");
iter<0,sizeof...(PosT)>( [&](auto i) { mB[i] = f[i]; }, NoF{} ); iter<0,sizeof...(PosT)>( [&](auto i) { std::get<i>(mB) = f[i].val(); }, NoF{} );
} }
template <class... PosT> template <class... PosT>
const Tuple<PosT...>& GMFormat<PosT...>::all() const const Tuple<PosT...>& GMFormat<PosT...>::all() const
{ {

View file

@ -44,7 +44,7 @@ namespace CNORXZ
template <SizeT L, class Index> template <SizeT L, class Index>
decltype(auto) lindexPtr(const Sptr<Index>& i) decltype(auto) lindexPtr(const Sptr<Index>& i)
{ {
return LIndex<Index,L>( i ); return std::make_shared<LIndex<Index,L>>( i );
} }
template <class Index, SizeT L> template <class Index, SizeT L>

View file

@ -29,6 +29,11 @@ namespace CNORXZ
Sptr<Index> mI; Sptr<Index> mI;
}; };
template <class Index, SizeT L>
struct is_index<LIndex<Index,L>>
{
static constexpr bool value = is_index<Index>::value;
};
template <class Index, SizeT L, class I1> template <class Index, SizeT L, class I1>
decltype(auto) operator*(const Sptr<LIndex<Index,L>>& a, const Sptr<I1>& b); decltype(auto) operator*(const Sptr<LIndex<Index,L>>& a, const Sptr<I1>& b);

View file

@ -27,10 +27,11 @@ namespace CNORXZ
typedef MRange<typename Indices::RangeType...> RangeType; typedef MRange<typename Indices::RangeType...> RangeType;
static constexpr SizeT NI = sizeof...(Indices); static constexpr SizeT NI = sizeof...(Indices);
INDEX_RANDOM_ACCESS_ITERATOR_DEFS(MetaType);
constexpr GMIndex() = default; constexpr GMIndex() = default;
constexpr GMIndex(GMIndex&& i) = default; constexpr GMIndex(GMIndex&& i) = default;
constexpr GMIndex& operator=(GMIndex&& i) = default; constexpr GMIndex& operator=(GMIndex&& i) = default;
// no defaults:
constexpr GMIndex(const GMIndex& i); constexpr GMIndex(const GMIndex& i);
constexpr GMIndex& operator=(const GMIndex& i); constexpr GMIndex& operator=(const GMIndex& i);
@ -103,7 +104,7 @@ namespace CNORXZ
Sptr<RangeType> mRange; Sptr<RangeType> mRange;
SPack<Indices...> mIPack; SPack<Indices...> mIPack;
typedef RemoveRef<decltype(mkLexFormat(mIPack,Isqr<0,NI-1>{}))> LexFormatT; typedef RemoveRef<decltype(mkLexFormat(mIPack,Isqr<1,NI>{}))> LexFormatT;
LexFormatT mLexFormat; LexFormatT mLexFormat;
FormatT mFormat; FormatT mFormat;
SizeT mLex; SizeT mLex;

View file

@ -4,10 +4,12 @@
#include "mrange.cc.h" #include "mrange.cc.h"
#include "xindex.cc.h" #include "xindex.cc.h"
#include "urange.cc.h" #include "urange.cc.h"
#include "srange.cc.h"
#include "crange.cc.h" #include "crange.cc.h"
#include "prange.cc.h" #include "prange.cc.h"
#include "dindex.cc.h" #include "dindex.cc.h"
#include "lindex.cc.h" #include "lindex.cc.h"
#include "eindex.cc.h"
#include "index_mul.cc.h" #include "index_mul.cc.h"
#include "index_pack.cc.h" #include "index_pack.cc.h"
#include "index_format.cc.h" #include "index_format.cc.h"

View file

@ -2,12 +2,15 @@
#include "range_base.h" #include "range_base.h"
#include "index_base.h" #include "index_base.h"
#include "mrange.h" #include "mrange.h"
#include "crange.h"
#include "prange.h"
#include "xindex.h" #include "xindex.h"
#include "yrange.h" #include "yrange.h"
#include "urange.h"
#include "srange.h"
#include "crange.h"
#include "prange.h"
#include "dindex.h" #include "dindex.h"
#include "lindex.h" #include "lindex.h"
#include "eindex.h"
#include "index_mul.h" #include "index_mul.h"
#include "index_pack.h" #include "index_pack.h"
#include "index_format.h" #include "index_format.h"

View file

@ -10,8 +10,8 @@ namespace CNORXZ
* SIndex * * SIndex *
**************/ **************/
template <typename Meta, SizeT S> template <typename MetaT, SizeT S>
SIndex<Meta,S>::SIndex(const RangePtr& range, SizeT pos) : SIndex<MetaT,S>::SIndex(const RangePtr& range, SizeT pos) :
IndexInterface<SIndex<MetaT,S>,MetaT>(pos), IndexInterface<SIndex<MetaT,S>,MetaT>(pos),
mRangePtr(rangeCast<RangeType>(range)), mRangePtr(rangeCast<RangeType>(range)),
mMetaPtr(&mRangePtr->get(0)) mMetaPtr(&mRangePtr->get(0))
@ -20,137 +20,137 @@ namespace CNORXZ
<< ", expected " << S); << ", expected " << S);
} }
template <typename Meta, SizeT S> template <typename MetaT, SizeT S>
SIndex& SIndex<Meta,S>::operator=(SizeT lexpos) SIndex<MetaT,S>& SIndex<MetaT,S>::operator=(SizeT lexpos)
{ {
IB::mPos = lexpos; IB::mPos = lexpos;
return *this; return *this;
} }
template <typename Meta, SizeT S> template <typename MetaT, SizeT S>
SIndex& SIndex<Meta,S>::operator++() SIndex<MetaT,S>& SIndex<MetaT,S>::operator++()
{ {
++IB::mPos; ++IB::mPos;
return *this; return *this;
} }
template <typename Meta, SizeT S> template <typename MetaT, SizeT S>
SIndex& SIndex<Meta,S>::operator--() SIndex<MetaT,S>& SIndex<MetaT,S>::operator--()
{ {
--IB::mPos; --IB::mPos;
return *this; return *this;
} }
template <typename Meta, SizeT S> template <typename MetaT, SizeT S>
SIndex SIndex<Meta,S>::operator+(Int n) const SIndex<MetaT,S> SIndex<MetaT,S>::operator+(Int n) const
{ {
return SIndex(mRangePtr, IB::mPos + n); return SIndex(mRangePtr, IB::mPos + n);
} }
template <typename Meta, SizeT S> template <typename MetaT, SizeT S>
SIndex SIndex<Meta,S>::operator-(Int n) const SIndex<MetaT,S> SIndex<MetaT,S>::operator-(Int n) const
{ {
return SIndex(mRangePtr, IB::mPos - n); return SIndex(mRangePtr, IB::mPos - n);
} }
template <typename Meta, SizeT S> template <typename MetaT, SizeT S>
SIndex& SIndex<Meta,S>::operator+=(Int n) SIndex<MetaT,S>& SIndex<MetaT,S>::operator+=(Int n)
{ {
IB::mPos += n; IB::mPos += n;
return *this; return *this;
} }
template <typename Meta, SizeT S> template <typename MetaT, SizeT S>
SIndex& SIndex<Meta,S>::operator-=(Int n) SIndex<MetaT,S>& SIndex<MetaT,S>::operator-=(Int n)
{ {
IB::mPos -= n; IB::mPos -= n;
return *this; return *this;
} }
template <typename Meta, SizeT S> template <typename MetaT, SizeT S>
SizeT SIndex<Meta,S>::lex() const SizeT SIndex<MetaT,S>::lex() const
{ {
return IB::mPos; return IB::mPos;
} }
template <typename Meta, SizeT S> template <typename MetaT, SizeT S>
SPos<S> SIndex<Meta,S>::pmax() const SPos<S> SIndex<MetaT,S>::pmax() const
{ {
return SPos<S>(); return SPos<S>();
} }
template <typename Meta, SizeT S> template <typename MetaT, SizeT S>
SPos<S> SIndex<Meta,S>::lmax() const SPos<S> SIndex<MetaT,S>::lmax() const
{ {
return SPos<S>(); return SPos<S>();
} }
template <typename Meta, SizeT S> template <typename MetaT, SizeT S>
IndexId<0> SIndex<Meta,S>::id() const IndexId<0> SIndex<MetaT,S>::id() const
{ {
return IndexId<0>(this->ptrId()); return IndexId<0>(this->ptrId());
} }
template <typename Meta, SizeT S> template <typename MetaT, SizeT S>
const MetaT& SIndex<Meta,S>::operator*() const const MetaT& SIndex<MetaT,S>::operator*() const
{ {
return mMetaPtr[IB::mPos]; return mMetaPtr[IB::mPos];
} }
template <typename Meta, SizeT S> template <typename MetaT, SizeT S>
SizeT SIndex<Meta,S>::dim() const SizeT SIndex<MetaT,S>::dim() const
{ {
return 1; return 1;
} }
template <typename Meta, SizeT S> template <typename MetaT, SizeT S>
Sptr<RangeType> SIndex<Meta,S>::range() const Sptr<SRange<MetaT,S>> SIndex<MetaT,S>::range() const
{ {
return mRangePtr; return mRangePtr;
} }
template <typename Meta, SizeT S> template <typename MetaT, SizeT S>
template <SizeT I> template <SizeT I>
UPos SIndex<Meta,S>::stepSize(const IndexId<I>& id) const UPos SIndex<MetaT,S>::stepSize(const IndexId<I>& id) const
{ {
return UPos(id == this->id() ? 1 : 0); return UPos(id == this->id() ? 1 : 0);
} }
template <typename Meta, SizeT S> template <typename MetaT, SizeT S>
String SIndex<Meta,S>::stringMeta() const String SIndex<MetaT,S>::stringMeta() const
{ {
return toString(this->meta()); return toString(this->meta());
} }
template <typename Meta, SizeT S> template <typename MetaT, SizeT S>
const MetaT& SIndex<Meta,S>::meta() const const MetaT& SIndex<MetaT,S>::meta() const
{ {
return mMetaPtr[IB::mPos]; return mMetaPtr[IB::mPos];
} }
template <typename Meta, SizeT S> template <typename MetaT, SizeT S>
SIndex& SIndex<Meta,S>::at(const MetaT& metaPos) SIndex<MetaT,S>& SIndex<MetaT,S>::at(const MetaT& metaPos)
{ {
(*this) = mRangePtr->getMeta(metaPos); (*this) = mRangePtr->getMeta(metaPos);
return *this; return *this;
} }
template <typename Meta, SizeT S> template <typename MetaT, SizeT S>
decltype(auto) SIndex<Meta,S>::xpr(const Sptr<SIndex<MetaType,S>>& _this) const decltype(auto) SIndex<MetaT,S>::xpr(const Sptr<SIndex<MetaType,S>>& _this) const
{ {
return coproot(mMetaPtr,_this); return coproot(mMetaPtr,_this);
} }
template <typename Meta, SizeT S> template <typename MetaT, SizeT S>
template <class Index> template <class Index>
decltype(auto) SIndex<Meta,S>::reformat(const Sptr<Index>& ind) const decltype(auto) SIndex<MetaT,S>::reformat(const Sptr<Index>& ind) const
{ {
return ind; return ind;
} }
template <typename Meta, SizeT S> template <typename MetaT, SizeT S>
template <class Index> template <class Index>
decltype(auto) SIndex<Meta,S>::slice(const Sptr<Index>& ind) const decltype(auto) SIndex<MetaT,S>::slice(const Sptr<Index>& ind) const
{ {
if(ind != nullptr){ if(ind != nullptr){
if(ind->dim() != 0) { if(ind->dim() != 0) {
@ -160,9 +160,9 @@ namespace CNORXZ
return std::make_shared<SIndex<MetaType,S>>(*this); return std::make_shared<SIndex<MetaType,S>>(*this);
} }
template <typename Meta, SizeT S> template <typename MetaT, SizeT S>
template <class Xpr, class F> template <class Xpr, class F>
decltype(auto) SIndex<Meta,S>::ifor(const Xpr& xpr, F&& f) const decltype(auto) SIndex<MetaT,S>::ifor(const Xpr& xpr, F&& f) const
{ {
return SFor<S,0,Xpr,F>(this->id(), xpr, std::forward<F>(f)); return SFor<S,0,Xpr,F>(this->id(), xpr, std::forward<F>(f));
} }
@ -183,7 +183,7 @@ namespace CNORXZ
mSpace(space) {} mSpace(space) {}
template <typename MetaType, SizeT S> template <typename MetaType, SizeT S>
SRangeFactory<MetaType,S>::SRangeFactory(Arr<MetaType,S>&& space) SRangeFactory<MetaType,S>::SRangeFactory(Arr<MetaType,S>&& space) :
mSpace(std::forward<Arr<MetaType,S>>(space)) {} mSpace(std::forward<Arr<MetaType,S>>(space)) {}
template <typename MetaType, SizeT S> template <typename MetaType, SizeT S>
@ -233,57 +233,67 @@ namespace CNORXZ
CXZ_ASSERT(itdupl == mSpace.end(), "found duplicate: " << *itdupl); CXZ_ASSERT(itdupl == mSpace.end(), "found duplicate: " << *itdupl);
} }
template <typename MetaType, SizeT S>
SizeT SRange<MetaType,S>::size() const SizeT SRange<MetaType,S>::size() const
{ {
return S; return S;
} }
template <typename MetaType, SizeT S>
SizeT SRange<MetaType,S>::dim() const SizeT SRange<MetaType,S>::dim() const
{ {
return 1; return 1;
} }
template <typename MetaType, SizeT S>
String SRange<MetaType,S>::stringMeta(SizeT pos) const String SRange<MetaType,S>::stringMeta(SizeT pos) const
{ {
return toString(mSpace[pos]); return toString(mSpace[pos]);
} }
template <typename MetaType, SizeT S>
const TypeInfo& SRange<MetaType,S>::type() const const TypeInfo& SRange<MetaType,S>::type() const
{ {
return typeid(SRange<MetaType,S>); return typeid(SRange<MetaType,S>);
} }
template <typename MetaType, SizeT S>
const TypeInfo& SRange<MetaType,S>::metaType() const const TypeInfo& SRange<MetaType,S>::metaType() const
{ {
return typeid(MetaType); return typeid(MetaType);
} }
template <typename MetaType, SizeT S>
RangePtr SRange<MetaType,S>::extend(const RangePtr& r) const RangePtr SRange<MetaType,S>::extend(const RangePtr& r) const
{ {
// TODO: check for selected static sizes of SRange -> return SRange!!! // TODO: check for selected static sizes of SRange -> return SRange!!!
auto rx = rangeCast<URange<MetaType>>(r); auto rx = rangeCast<URange<MetaType>>(r);
Vector<MetaType> space(mSpace.begin(), mSpace.end()); Vector<MetaType> space(mSpace.begin(), mSpace.end());
space.insert(space.end(), rx->mSpace.begin(), rx->mSpace.end()); space.insert(space.end(), rx->begin(), rx->end());
return URangeFactory<MetaType>( space ).create(); return URangeFactory<MetaType>( space ).create();
} }
const MetaType& SRange<MetaType,S>::get(SizeT pos) const; template <typename MetaType, SizeT S>
const MetaType& SRange<MetaType,S>::get(SizeT pos) const
{ {
return mSpace[pos]; return mSpace[pos];
} }
const MetaType* SRange<MetaType,S>::get() const; template <typename MetaType, SizeT S>
const MetaType* SRange<MetaType,S>::get() const
{ {
return mSpace.data(); return mSpace.data();
} }
SizeT SRange<MetaType,S>::getMeta(const MetaType& metaPos) const; template <typename MetaType, SizeT S>
SizeT SRange<MetaType,S>::getMeta(const MetaType& metaPos) const
{ {
auto b = mSpace.begin(); auto b = mSpace.begin();
auto e = mSpace.end(); auto e = mSpace.end();
return std::lower_bound(b, e, meta, std::less<MetaType>()) - b; return std::lower_bound(b, e, metaPos, std::less<MetaType>()) - b;
} }
template <typename MetaType, SizeT S>
Vector<Uuid> SRange<MetaType,S>::key() const Vector<Uuid> SRange<MetaType,S>::key() const
{ {
return Vector<Uuid> { this->id() }; return Vector<Uuid> { this->id() };
@ -298,10 +308,10 @@ namespace CNORXZ
{ {
Sptr<URange<MetaType>> tmp; Sptr<URange<MetaType>> tmp;
if(r->type() != typeid(URange<MetaType>)){ if(r->type() != typeid(URange<MetaType>)){
tmp = castRange<URange<MetaType>>(r); tmp = rangeCast<URange<MetaType>>(r);
} }
else { else {
tmp = r; tmp = std::dynamic_pointer_cast<URange<MetaType>>(r);
} }
CXZ_ASSERT(tmp->size() == S, "cannot cast range of size " << tmp->size() CXZ_ASSERT(tmp->size() == S, "cannot cast range of size " << tmp->size()
<< " into static range of size " << S); << " into static range of size " << S);

View file

@ -10,7 +10,7 @@
namespace CNORXZ namespace CNORXZ
{ {
template <typename Meta, SizeT S> template <typename MetaT, SizeT S>
class SIndex : public IndexInterface<SIndex<MetaT,S>,MetaT> class SIndex : public IndexInterface<SIndex<MetaT,S>,MetaT>
{ {
public: public:
@ -18,6 +18,8 @@ namespace CNORXZ
typedef SRange<MetaT,S> RangeType; typedef SRange<MetaT,S> RangeType;
typedef MetaT MetaType; typedef MetaT MetaType;
INDEX_RANDOM_ACCESS_ITERATOR_DEFS(MetaType);
DEFAULT_MEMBERS(SIndex);
SIndex(const RangePtr& range, SizeT pos = 0); SIndex(const RangePtr& range, SizeT pos = 0);
SIndex& operator=(SizeT lexpos); SIndex& operator=(SizeT lexpos);
@ -119,6 +121,7 @@ namespace CNORXZ
{ {
static Sptr<SRange<MetaType,S>> func(const RangePtr& r); static Sptr<SRange<MetaType,S>> func(const RangePtr& r);
}; };
} }
#endif #endif

View file

@ -8,6 +8,8 @@
#include "ranges/range_base.h" #include "ranges/range_base.h"
#include "xpr/xpr.h" #include "xpr/xpr.h"
#include <iterator>
namespace CNORXZ namespace CNORXZ
{ {
@ -20,13 +22,18 @@ namespace CNORXZ
typedef URange<MetaT> RangeType; typedef URange<MetaT> RangeType;
typedef MetaT MetaType; typedef MetaT MetaType;
INDEX_RANDOM_ACCESS_ITERATOR_DEFS(MetaType);
DEFAULT_MEMBERS(UIndex);
UIndex(const RangePtr& range, SizeT pos = 0); UIndex(const RangePtr& range, SizeT pos = 0);
void swap(UIndex& i) {}; // !!!
UIndex& operator=(SizeT lexpos); UIndex& operator=(SizeT lexpos);
UIndex& operator++(); UIndex& operator++();
UIndex& operator--(); UIndex& operator--();
UIndex operator+(Int n) const; UIndex operator+(Int n) const;
UIndex operator-(Int n) const; UIndex operator-(Int n) const;
SizeT operator-(const UIndex& i) const { return lex() - i.lex(); } // !!!
UIndex& operator+=(Int n); UIndex& operator+=(Int n);
UIndex& operator-=(Int n); UIndex& operator-=(Int n);
@ -62,6 +69,9 @@ namespace CNORXZ
const MetaT* mMetaPtr; const MetaT* mMetaPtr;
}; };
template <typename MetaT>
void swap(UIndex<MetaT>& a, UIndex<MetaT>& b) { a.swap(b); }
template <typename MetaType, class I1> template <typename MetaType, class I1>
decltype(auto) operator*(const Sptr<UIndex<MetaType>>& a, const Sptr<I1>& b); decltype(auto) operator*(const Sptr<UIndex<MetaType>>& a, const Sptr<I1>& b);

View file

@ -19,10 +19,11 @@ namespace CNORXZ
typedef YRange RangeType; typedef YRange RangeType;
typedef Vector<DType> MetaType; typedef Vector<DType> MetaType;
INDEX_RANDOM_ACCESS_ITERATOR_DEFS(MetaType);
YIndex() = default; YIndex() = default;
YIndex(YIndex&& i) = default; YIndex(YIndex&& i) = default;
YIndex& operator=(YIndex&& i) = default; YIndex& operator=(YIndex&& i) = default;
// no defaults:
YIndex(const YIndex& i); YIndex(const YIndex& i);
YIndex& operator=(const YIndex& i); YIndex& operator=(const YIndex& i);

View file

@ -98,9 +98,10 @@ namespace
{ {
protected: protected:
typedef MIndex<CIndex,LIndex<CIndex,2>,EIndex<SizeT,4,1>> MCCI; typedef MIndex<CIndex,LIndex<CIndex,2>,EIndex<SizeT,4,1>> MCCI1;
typedef MIndex<LIndex<CIndex,2>,EIndex<SizeT,4,1>,CIndex> MCCI2;
OpCont_CR_CR_Test() OpCont_CR_CR_Test2()
{ {
mSize1 = 12; mSize1 = 12;
mSize2 = 11; mSize2 = 11;
@ -115,8 +116,8 @@ namespace
mCI1j = std::make_shared<CIndex>(cr1); mCI1j = std::make_shared<CIndex>(cr1);
mCI2i = std::make_shared<CIndex>(cr2); mCI2i = std::make_shared<CIndex>(cr2);
mCI2j = std::make_shared<CIndex>(cr2); mCI2j = std::make_shared<CIndex>(cr2);
mCC1i1j = mindexPtr(mCI1i*eplex(mCI1j,4,1,2)); mCC1i1j = mindexPtr(mCI1i*eplex<4,1,2>(mCI1j));
mCC1j1i = mindexPtr(eplex(mCI1j,4,1,2)*mCI1i); mCC1j1i = mindexPtr(eplex<4,1,2>(mCI1j)*mCI1i);
mOC1i1j.init(mCC1i1j); mOC1i1j.init(mCC1i1j);
mOR1j1i.init(mData11.data(), mCC1j1i); mOR1j1i.init(mData11.data(), mCC1j1i);
mOR1i1j.init(mData11.data(), mCC1i1j); mOR1i1j.init(mData11.data(), mCC1i1j);
@ -132,11 +133,11 @@ namespace
Sptr<CIndex> mCI1j; Sptr<CIndex> mCI1j;
Sptr<CIndex> mCI2i; Sptr<CIndex> mCI2i;
Sptr<CIndex> mCI2j; Sptr<CIndex> mCI2j;
Sptr<MCCI> mCC1i1j; Sptr<MCCI1> mCC1i1j;
Sptr<MCCI> mCC1j1i; Sptr<MCCI2> mCC1j1i;
OpCont<double,MCCI> mOC1i1j; OpCont<double,MCCI1> mOC1i1j;
COpRoot<double,MCCI> mOR1j1i; COpRoot<double,MCCI2> mOR1j1i;
COpRoot<double,MCCI> mOR1i1j; COpRoot<double,MCCI1> mOR1i1j;
}; };
TEST_F(OpCont_CR_Test, Basics) TEST_F(OpCont_CR_Test, Basics)