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

View file

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

View file

@ -8,7 +8,7 @@ namespace
using namespace CNORXZ; using namespace CNORXZ;
template <class PosT1, class PosT2> 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); return MPos<PosT1,PosT2>(a,b);
} }
@ -84,17 +84,17 @@ namespace
EXPECT_EQ(mp4.size(), 2); EXPECT_EQ(mp4.size(), 2);
EXPECT_EQ(mp5.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(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(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(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(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(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()); EXPECT_EQ(mp5.next().val(), mS4p.val() * mUp1.val());
} }
/* /*