DPos/DPosRef: -> static scalar; replace next() by sub()

This commit is contained in:
Christian Zimmermann 2022-10-22 01:11:27 +02:00
parent f68c02565d
commit e3fe04d5da
3 changed files with 31 additions and 200 deletions

View file

@ -7,28 +7,6 @@
namespace CNORXZ
{
/****************
* VPosBase *
****************/
/*
template <SizeT N>
inline Uptr<VPosBase> VPosBase::vextend(const SPos<N>& a) const
{
return this->vextend(UPos(N));
}
template <SizeT N, SizeT... Ms>
inline Uptr<VPosBase> VPosBase::vextend(const SFPos<N,Ms...>& a) const
{
return this->vextend(static_cast<FPos>(a));
}
template <class PosT1, class PosT2>
inline Uptr<VPosBase> VPosBase::vextend(const MPos<PosT1,PosT2>& a) const
{
return this->vextend(static_cast<const PosT1&>(a))->vextend(a.next());
}
*/
/************
* VPos *
************/
@ -88,35 +66,7 @@ namespace CNORXZ
typedef decltype((*this)(UPos(a->vval()))) OPosT;
return std::make_unique<VPos<OPosT>>( (*this)(UPos(a->vval())) );
}
/*
template <class PosT>
Uptr<VPosBase> VPos<PosT>::vextend(const UPos& a) const
{
typedef decltype(this->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(this->extend(a));
}
template <class PosT>
Uptr<VPosBase> VPos<PosT>::vextend(const FPos& a) const
{
typedef decltype(this->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(this->extend(a));
}
template <class PosT>
Uptr<VPosBase> VPos<PosT>::vextend(const DPos& a) const
{
typedef decltype(this->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(this->extend(a));
}
template <class PosT>
Uptr<VPosBase> VPos<PosT>::vextend(const DPosRef& a) const
{
typedef decltype(this->extend(DPos(a))) OPosT;
return std::make_unique<VPos<OPosT>>(this->extend(DPos(a)));
}
*/
/******************
* VPos<MPos> *
******************/
@ -190,8 +140,8 @@ namespace CNORXZ
template <class PosT1, class PosT2>
Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vplus(const VPosBase* a) const
{
typedef decltype((*this) + DPosRef(a)) OPosT;
return std::make_unique<VPos<OPosT>>((*this) + DPosRef(a));
typedef decltype((*this) + PosFromVPos<MPos<PosT1,PosT2>>::make(a)) OPosT;
return std::make_unique<VPos<OPosT>>((*this) + PosFromVPos<MPos<PosT1,PosT2>>::make(a));
}
template <class PosT1, class PosT2>
@ -207,35 +157,7 @@ namespace CNORXZ
typedef decltype( (*this)(UPos(a->vval())) ) OPosT;
return std::make_unique<VPos<OPosT>>( (*this)(UPos(a->vval())) );
}
/*
template <class PosT1, class PosT2>
Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vextend(const UPos& a) const
{
typedef decltype(this->extend(DPos(a))) OPosT;
return std::make_unique<VPos<OPosT>>(this->extend(DPos(a)));
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vextend(const FPos& a) const
{
typedef decltype(this->extend(DPos(a))) OPosT;
return std::make_unique<VPos<OPosT>>(this->extend(DPos(a)));
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vextend(const DPos& a) const
{
typedef decltype(this->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(this->extend(a));
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vextend(const DPosRef& a) const
{
typedef decltype(this->extend(DPos(a))) OPosT;
return std::make_unique<VPos<OPosT>>(this->extend(DPos(a)));
}
*/
/***************
* VPosRef *
***************/
@ -295,35 +217,7 @@ namespace CNORXZ
typedef decltype( (*mC)(UPos(a->vval())) ) OPosT;
return std::make_unique<VPos<OPosT>>( (*mC)(UPos(a->vval())) );
}
/*
template <class PosT>
Uptr<VPosBase> VPosRef<PosT>::vextend(const UPos& a) const
{
typedef decltype(mC->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(mC->extend(a));
}
template <class PosT>
Uptr<VPosBase> VPosRef<PosT>::vextend(const FPos& a) const
{
typedef decltype(mC->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(mC->extend(a));
}
template <class PosT>
Uptr<VPosBase> VPosRef<PosT>::vextend(const DPos& a) const
{
typedef decltype(mC->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(mC->extend(a));
}
template <class PosT>
Uptr<VPosBase> VPosRef<PosT>::vextend(const DPosRef& a) const
{
typedef decltype(mC->extend(DPos(a))) OPosT;
return std::make_unique<VPos<OPosT>>(mC->extend(DPos(a)));
}
*/
/*********************
* VPosRef<MPos> *
*********************/
@ -376,8 +270,8 @@ namespace CNORXZ
template <class PosT1, class PosT2>
Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vplus(const VPosBase* a) const
{
typedef decltype((*mC) + DPosRef(a)) OPosT;
return std::make_unique<VPos<OPosT>>((*mC) + DPosRef(a));
typedef decltype((*mC) + PosFromVPos<MPos<PosT1,PosT2>>::make(a)) OPosT;
return std::make_unique<VPos<OPosT>>((*mC) + PosFromVPos<MPos<PosT1,PosT2>>::make(a));
}
template <class PosT1, class PosT2>
@ -393,35 +287,25 @@ namespace CNORXZ
typedef decltype( (*mC)(UPos(a->vval())) ) OPosT;
return std::make_unique<VPos<OPosT>>( (*mC)(UPos(a->vval())) );
}
/*
template <class PosT1, class PosT2>
Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vextend(const UPos& a) const
/*******************
* PosFromVPos *
*******************/
template <class PosT>
inline decltype(auto) PosFromVPos<PosT>::make(const VPosBase* a)
{
typedef decltype(mC->extend(DPos(a))) OPosT;
return std::make_unique<VPos<OPosT>>(mC->extend(DPos(a)));
return PosT(a->vval());
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vextend(const FPos& a) const
inline decltype(auto) PosFromVPos<MPos<PosT1,PosT2>>::make(const VPosBase* a)
{
typedef decltype(mC->extend(DPos(a))) OPosT;
return std::make_unique<VPos<OPosT>>(mC->extend(DPos(a)));
#if CXZ_DEBUG
CXZ_ASSERT(a->vnext() != nullptr, "VPos does not match required size");
#endif
return MPos<PosT1,PosT2>(a->vval(), PosFromVPos<PosT2>::make(a->vnext()));
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vextend(const DPos& a) const
{
typedef decltype(mC->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(mC->extend(a));
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vextend(const DPosRef& a) const
{
typedef decltype(mC->extend(DPos(a))) OPosT;
return std::make_unique<VPos<OPosT>>(mC->extend(DPos(a)));
}
*/
}
#endif

View file

@ -4,8 +4,6 @@
#include "base/base.h"
#define MAX_VMPOS_DEPTH 4
namespace CNORXZ
{
class VPosBase
@ -21,20 +19,6 @@ namespace CNORXZ
virtual Uptr<VPosBase> vplus(const VPosBase* a) const = 0;
virtual Uptr<VPosBase> vtimes(const VPosBase* a) const = 0;
virtual Uptr<VPosBase> vexec(const VPosBase* a) const = 0;
//virtual Uptr<VPosBase> vextend(const UPos& a) const = 0;
//virtual Uptr<VPosBase> vextend(const FPos& a) const = 0;
//virtual Uptr<VPosBase> vextend(const DPos& a) const = 0;
//virtual Uptr<VPosBase> vextend(const DPosRef& a) const = 0;
/*
template <SizeT N>
inline Uptr<VPosBase> vextend(const SPos<N>& a) const;
template <SizeT N, SizeT... Ms>
inline Uptr<VPosBase> vextend(const SFPos<N,Ms...>& a) const;
template <class PosT1, class PosT2>
inline Uptr<VPosBase> vextend(const MPos<PosT1,PosT2>& a) const;
*/
};
template <class PosT>
@ -53,10 +37,6 @@ namespace CNORXZ
virtual Uptr<VPosBase> vplus(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vtimes(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vexec(const VPosBase* a) const override final;
//virtual Uptr<VPosBase> vextend(const UPos& a) const override final;
//virtual Uptr<VPosBase> vextend(const FPos& a) const override final;
//virtual Uptr<VPosBase> vextend(const DPos& a) const override final;
//virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final;
};
template <class PosT1, class PosT2>
@ -81,10 +61,6 @@ namespace CNORXZ
virtual Uptr<VPosBase> vplus(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vtimes(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vexec(const VPosBase* a) const override final;
//virtual Uptr<VPosBase> vextend(const UPos& a) const override final;
//virtual Uptr<VPosBase> vextend(const FPos& a) const override final;
//virtual Uptr<VPosBase> vextend(const DPos& a) const override final;
//virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final;
};
template <class PosT>
@ -105,10 +81,6 @@ namespace CNORXZ
virtual Uptr<VPosBase> vplus(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vtimes(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vexec(const VPosBase* a) const override final;
//virtual Uptr<VPosBase> vextend(const UPos& a) const override final;
//virtual Uptr<VPosBase> vextend(const FPos& a) const override final;
//virtual Uptr<VPosBase> vextend(const DPos& a) const override final;
//virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final;
};
@ -133,10 +105,6 @@ namespace CNORXZ
virtual Uptr<VPosBase> vplus(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vtimes(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vexec(const VPosBase* a) const override final;
//virtual Uptr<VPosBase> vextend(const UPos& a) const override final;
//virtual Uptr<VPosBase> vextend(const FPos& a) const override final;
//virtual Uptr<VPosBase> vextend(const DPos& a) const override final;
//virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final;
};
@ -180,6 +148,17 @@ namespace CNORXZ
class VPosRef<DPosRef>
{};
template <class PosT>
struct PosFromVPos
{
static inline decltype(auto) make(const VPosBase* a);
};
template <class PosT1, class PosT2>
struct PosFromVPos<MPos<PosT1,PosT2>>
{
static inline decltype(auto) make(const VPosBase* a);
};
}

View file

@ -157,38 +157,6 @@ namespace
EXPECT_EQ(dp5.sub().val(), mS4p.val() * mUp1.val());
}
TEST_F(Pos_Test, DynExtend)
{/*
DPos dp1(mkMPos(static_cast<UPos>(mS2p), mUp1));
DPos dp2(mkMPos(mUp2, static_cast<UPos>(mS4p)));
auto dp3 = dp1.extend(mUp2);
auto dp4 = dp2.extend(mS2p);
auto dp5 = dp3 + dp4;
DPos dp01(mUp1);
auto dp6 = dp3 * dp01;
EXPECT_EQ( dp3.size(), 3u );
EXPECT_EQ( dp4.size(), 3u );
EXPECT_EQ( dp3.val(), mS2p.val() );
EXPECT_EQ( dp3.next().val(), mUp1.val() );
EXPECT_EQ( dp3.next().next().val(), mUp2.val() );
EXPECT_EQ( dp4.val(), mUp2.val() );
EXPECT_EQ( dp4.next().val(), mS4p.val() );
EXPECT_EQ( dp4.next().next().val(), mS2p.val() );
EXPECT_EQ( dp5.size(), 3u );
EXPECT_EQ( dp6.size(), 3u );
EXPECT_EQ( dp5.val(), dp3.val() + dp4.val() );
EXPECT_EQ( dp5.next().val(), dp3.next().val() + dp4.next().val() );
EXPECT_EQ( dp5.next().next().val(), dp3.next().next().val() + dp4.next().next().val() );
EXPECT_EQ( dp6.val(), dp3.val() * dp01.val() );
EXPECT_EQ( dp6.next().val(), dp3.next().val() * dp01.val() );
EXPECT_EQ( dp6.next().next().val(), dp3.next().next().val() * dp01.val() );
*/}
}
int main(int argc, char** argv)