PosT: again linear

This commit is contained in:
Christian Zimmermann 2022-10-09 16:59:12 +02:00
parent a142fdb466
commit 7e1cfa6b3a
3 changed files with 33 additions and 18 deletions

View file

@ -132,7 +132,7 @@ namespace CNORXZ
}
template <class PosT>
constexpr FPos UPos::operator*(const PosT& in) const
constexpr FPos FPos::operator*(const PosT& in) const
{
return FPos(mExt * in.val(), mMap);
}
@ -153,6 +153,9 @@ namespace CNORXZ
* SFPos *
*************/
template <SizeT N, SizeT... Ms>
Arr<SizeT,sizeof...(Ms)> SFPos<N,Ms...>::sMs = { Ms... };
template <SizeT N, SizeT... Ms>
constexpr SizeT SFPos<N,Ms...>::size() const
{
@ -194,11 +197,9 @@ namespace CNORXZ
}
template <SizeT N, SizeT... Ms>
template <SizeT N1>
constexpr auto SFPos<N,Ms...>::operator*(const UPos& a) const
{
static const Arr<SizeT,sizeof...(Ms)> ms({ Ms... });
return FPos(N * a.val(), &ms[0]);
return FPos(N * a.val(), &sMs[0]);
}
template <SizeT N, SizeT... Ms>
@ -226,6 +227,14 @@ namespace CNORXZ
"MPos has to be derived from scalar pos type");
}
template <class BPosT, class NPosT>
constexpr MPos<BPosT,NPosT>::MPos(const BPosT& b, const NPosT& n) :
BPosT(b), mNext(n)
{
static_assert(is_scalar_pos_type<BPosT>::value,
"MPos has to be derived from scalar pos type");
}
template <class BPosT, class NPosT>
template <typename... Args>
constexpr MPos<BPosT,NPosT>::MPos(Args&&... args, const NPosT& next) :
@ -251,7 +260,7 @@ namespace CNORXZ
}
template <class BPosT, class NPosT>
constexpr const NPos& MPos<BPosT,NPosT>::next() const
constexpr const NPosT& MPos<BPosT,NPosT>::next() const
{
return mNext;
}
@ -270,8 +279,8 @@ namespace CNORXZ
constexpr auto MPos<BPosT,NPosT>::operator*(const PosT& a) const
{
typedef decltype(BPosT::operator*(a)) OBPosT;
typedef decltype(mNext * a.next()) ONPosT;
return MPos<OBPosT,ONPosT>( BPosT::operator*(a), mNext * a.next() );
typedef decltype(mNext * a) ONPosT;
return MPos<OBPosT,ONPosT>( BPosT::operator*(a), mNext * a );
}
template <class BPosT, class NPosT>
@ -279,8 +288,8 @@ namespace CNORXZ
constexpr auto MPos<BPosT,NPosT>::operator()(const PosT& a) const
{
typedef decltype(BPosT::operator()(a)) OBPosT;
typedef decltype(mNext(a.next())) ONPosT;
return MPos<OBPosT,ONPosT>( BPosT::operator()(a), mNext(a.next()) );
typedef decltype(mNext(a)) ONPosT;
return MPos<OBPosT,ONPosT>( BPosT::operator()(a), mNext(a) );
}
template <class BPosT, class NPosT>

View file

@ -21,6 +21,8 @@ namespace CNORXZ
{
public:
constexpr SPos() = default;
constexpr SPos(const SPos& a) = default;
constexpr SPos(SPos&& a) = default;
constexpr SizeT size() const;
constexpr SizeT val() const;
@ -96,6 +98,8 @@ namespace CNORXZ
template <SizeT N, SizeT... Ms>
class SFPos
{
private:
static Arr<SizeT,sizeof...(Ms)> sMs;
public:
constexpr SFPos() = default;
@ -123,7 +127,9 @@ namespace CNORXZ
protected:
NPosT mNext;
public:
constexpr MPos()
constexpr MPos();
constexpr MPos(const BPosT& b, const NPosT& n);
template <typename... Args>
constexpr MPos(Args&&... args, const NPosT& next);
@ -132,7 +138,7 @@ namespace CNORXZ
constexpr MPos(Args&&... args, NPosT&& next);
constexpr SizeT size() const;
constexpr const NPos& next() const;
constexpr const NPosT& next() const;
template <class PosT>
constexpr auto operator+(const PosT& a) const;

View file

@ -8,7 +8,7 @@ namespace
using namespace CNORXZ;
template <class PosT1, class PosT2>
constexpr auto mkMPos(const CPosInterface<PosT1>& a, const CPosInterface<PosT2>& b)
constexpr auto mkMPos(const PosT1& a, const PosT2& b)
{
return MPos<PosT1,PosT2>(a,b);
}
@ -84,17 +84,17 @@ namespace
EXPECT_EQ(mp4.size(), 2);
EXPECT_EQ(mp5.size(), 2);
EXPECT_EQ(mp1.first().val(), mS2p.val());
EXPECT_EQ(mp1.val(), mS2p.val());
EXPECT_EQ(mp1.next().val(), mUp1.val());
EXPECT_EQ(mp2.first().val(), mUp2.val());
EXPECT_EQ(mp2.val(), mUp2.val());
EXPECT_EQ(mp2.next().val(), mS4p.val());
EXPECT_EQ(mp3a.first().val(), mS2p.val() + mUp2.val());
EXPECT_EQ(mp3a.val(), mS2p.val() + mUp2.val());
EXPECT_EQ(mp3a.next().val(), mUp1.val() + mS4p.val());
EXPECT_EQ(mp3b.first().val(), mS2p.val() + mUp2.val());
EXPECT_EQ(mp3b.val(), mS2p.val() + mUp2.val());
EXPECT_EQ(mp3b.next().val(), mUp1.val() + mS4p.val());
EXPECT_EQ(mp4.first().val(), mS2p.val() * mS2p.val());
EXPECT_EQ(mp4.val(), mS2p.val() * mS2p.val());
EXPECT_EQ(mp4.next().val(), mUp1.val() * mS2p.val());
EXPECT_EQ(mp5.first().val(), mUp2.val() * mUp1.val());
EXPECT_EQ(mp5.val(), mUp2.val() * mUp1.val());
EXPECT_EQ(mp5.next().val(), mS4p.val() * mUp1.val());
}
/*