add operator- Index

This commit is contained in:
Christian Zimmermann 2023-10-29 22:03:45 +01:00
parent 04af9ec3e8
commit 0e616f8370
16 changed files with 56 additions and 3 deletions

View file

@ -26,6 +26,7 @@ namespace CNORXZ
CIndex& operator--(); CIndex& operator--();
CIndex operator+(Int n) const; CIndex operator+(Int n) const;
CIndex operator-(Int n) const; CIndex operator-(Int n) const;
SizeT operator-(const CIndex& i) const;
CIndex& operator+=(Int n); CIndex& operator+=(Int n);
CIndex& operator-=(Int n); CIndex& operator-=(Int n);

View file

@ -32,6 +32,7 @@ namespace CNORXZ
DIndex& operator--(); DIndex& operator--();
DIndex operator+(Int n) const; DIndex operator+(Int n) const;
DIndex operator-(Int n) const; DIndex operator-(Int n) const;
SizeT operator-(const DIndex& i) const;
DIndex& operator+=(Int n); DIndex& operator+=(Int n);
DIndex& operator-=(Int n); DIndex& operator-=(Int n);

View file

@ -299,6 +299,12 @@ namespace CNORXZ
return o -= n; return o -= n;
} }
template <class FormatT, class... Indices>
SizeT GMIndex<FormatT,Indices...>::operator-(const GMIndex& i) const
{
return lex() - i.lex();
}
template <class FormatT, class... Indices> template <class FormatT, class... Indices>
GMIndex<FormatT,Indices...>& GMIndex<FormatT,Indices...>::operator+=(Int n) GMIndex<FormatT,Indices...>& GMIndex<FormatT,Indices...>::operator+=(Int n)
{ {

View file

@ -47,6 +47,7 @@ namespace CNORXZ
GMIndex& operator--(); GMIndex& operator--();
GMIndex operator+(Int n) const; GMIndex operator+(Int n) const;
GMIndex operator-(Int n) const; GMIndex operator-(Int n) const;
SizeT operator-(const GMIndex& i) const;
GMIndex& operator+=(Int n); GMIndex& operator+=(Int n);
GMIndex& operator-=(Int n); GMIndex& operator-=(Int n);

View file

@ -52,6 +52,12 @@ namespace CNORXZ
return PIndex(mRangePtr, IB::mPos + n); return PIndex(mRangePtr, IB::mPos + n);
} }
template <class IndexT>
SizeT PIndex<IndexT>::operator-(const PIndex& i) const
{
return lex() - i.lex();
}
template <class IndexT> template <class IndexT>
PIndex<IndexT> PIndex<IndexT>::operator-(Int n) const PIndex<IndexT> PIndex<IndexT>::operator-(Int n) const
{ {

View file

@ -26,6 +26,7 @@ namespace CNORXZ
PIndex& operator--(); PIndex& operator--();
PIndex operator+(Int n) const; PIndex operator+(Int n) const;
PIndex operator-(Int n) const; PIndex operator-(Int n) const;
SizeT operator-(const PIndex& i) const;
PIndex& operator+=(Int n); PIndex& operator+=(Int n);
PIndex& operator-=(Int n); PIndex& operator-=(Int n);

View file

@ -54,6 +54,12 @@ namespace CNORXZ
return SIndex(mRangePtr, IB::mPos - n); return SIndex(mRangePtr, IB::mPos - n);
} }
template <typename MetaT, SizeT S>
SizeT SIndex<MetaT,S>::operator-(const SIndex& i) const
{
return lex() - i.lex();
}
template <typename MetaT, SizeT S> template <typename MetaT, SizeT S>
SIndex<MetaT,S>& SIndex<MetaT,S>::operator+=(Int n) SIndex<MetaT,S>& SIndex<MetaT,S>::operator+=(Int n)
{ {

View file

@ -27,6 +27,7 @@ namespace CNORXZ
SIndex& operator--(); SIndex& operator--();
SIndex operator+(Int n) const; SIndex operator+(Int n) const;
SIndex operator-(Int n) const; SIndex operator-(Int n) const;
SizeT operator-(const SIndex& i) const;
SIndex& operator+=(Int n); SIndex& operator+=(Int n);
SIndex& operator-=(Int n); SIndex& operator-=(Int n);

View file

@ -58,6 +58,12 @@ namespace CNORXZ
return UIndex(mRangePtr, IB::mPos - n); return UIndex(mRangePtr, IB::mPos - n);
} }
template <typename MetaT>
SizeT UIndex<MetaT>::operator-(const UIndex& i) const
{
return lex() - i.lex();
}
template <typename MetaT> template <typename MetaT>
UIndex<MetaT>& UIndex<MetaT>::operator+=(Int n) UIndex<MetaT>& UIndex<MetaT>::operator+=(Int n)
{ {

View file

@ -26,14 +26,12 @@ namespace CNORXZ
DEFAULT_MEMBERS(UIndex); 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(); } // !!! SizeT operator-(const UIndex& i) const;
UIndex& operator+=(Int n); UIndex& operator+=(Int n);
UIndex& operator-=(Int n); UIndex& operator-=(Int n);

View file

@ -65,6 +65,14 @@ namespace CNORXZ
return std::make_shared<XIndex<Index,Meta>>(*mI - n); return std::make_shared<XIndex<Index,Meta>>(*mI - n);
} }
template <class Index, typename Meta>
SizeT XIndex<Index,Meta>::operator-(const XIndexBase& i) const
{
const XIndex<Index,Meta>* ip = dynamic_cast<const XIndex<Index,Meta>*>(&i);
CXZ_ASSERT(ip != nullptr, "bad index type");
return (*mI) - (*ip->mI);
}
template <class Index, typename Meta> template <class Index, typename Meta>
XIndex<Index,Meta>& XIndex<Index,Meta>::operator+=(Int n) XIndex<Index,Meta>& XIndex<Index,Meta>::operator+=(Int n)
{ {

View file

@ -25,6 +25,7 @@ namespace CNORXZ
virtual XIndexBase& operator--() = 0; virtual XIndexBase& operator--() = 0;
virtual XIndexPtr operator+(Int n) const = 0; virtual XIndexPtr operator+(Int n) const = 0;
virtual XIndexPtr operator-(Int n) const = 0; virtual XIndexPtr operator-(Int n) const = 0;
virtual SizeT operator-(const XIndexBase& i) const = 0;
virtual XIndexBase& operator+=(Int n) = 0; virtual XIndexBase& operator+=(Int n) = 0;
virtual XIndexBase& operator-=(Int n) = 0; virtual XIndexBase& operator-=(Int n) = 0;
@ -80,6 +81,7 @@ namespace CNORXZ
virtual XIndex& operator--() override final; virtual XIndex& operator--() override final;
virtual XIndexPtr operator+(Int n) const override final; virtual XIndexPtr operator+(Int n) const override final;
virtual XIndexPtr operator-(Int n) const override final; virtual XIndexPtr operator-(Int n) const override final;
virtual SizeT operator-(const XIndexBase& i) const override final;
virtual XIndex& operator+=(Int n) override final; virtual XIndex& operator+=(Int n) override final;
virtual XIndex& operator-=(Int n) override final; virtual XIndex& operator-=(Int n) override final;

View file

@ -38,6 +38,7 @@ namespace CNORXZ
YIndex& operator--(); YIndex& operator--();
YIndex operator+(Int n) const; // equivalent to applying n times ++ YIndex operator+(Int n) const; // equivalent to applying n times ++
YIndex operator-(Int n) const; YIndex operator-(Int n) const;
SizeT operator-(const YIndex& i) const;
YIndex& operator+=(Int n); YIndex& operator+=(Int n);
YIndex& operator-=(Int n); YIndex& operator-=(Int n);

View file

@ -41,6 +41,11 @@ namespace CNORXZ
return CIndex(mRangePtr, IB::mPos - n); return CIndex(mRangePtr, IB::mPos - n);
} }
SizeT CIndex::operator-(const CIndex& i) const
{
return lex() - i.lex();
}
CIndex& CIndex::operator+=(Int n) CIndex& CIndex::operator+=(Int n)
{ {
IB::mPos += n; IB::mPos += n;

View file

@ -75,6 +75,11 @@ namespace CNORXZ
return (*mI) - n; return (*mI) - n;
} }
SizeT DIndex::operator-(const DIndex& i) const
{
return (*mI) - (*i.mI);
}
DIndex& DIndex::operator+=(Int n) DIndex& DIndex::operator+=(Int n)
{ {
(*mI) += n; (*mI) += n;

View file

@ -247,6 +247,11 @@ namespace CNORXZ
return o -= n; return o -= n;
} }
SizeT YIndex::operator-(const YIndex& i) const
{
return lex() - i.lex();
}
YIndex& YIndex::operator+=(Int n) YIndex& YIndex::operator+=(Int n)
{ {
if(static_cast<Int>(lex()) + n < 0){ if(static_cast<Int>(lex()) + n < 0){