From 7e1cfa6b3acb210d50311fd047c3c22a9bf0270f Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Sun, 9 Oct 2022 16:59:12 +0200 Subject: [PATCH] PosT: again linear --- src/include/ranges/xfor/pos_type.cc.h | 27 ++++++++++++++++++--------- src/include/ranges/xfor/pos_type.h | 10 ++++++++-- src/tests/xfor_unit_test.cc | 14 +++++++------- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/include/ranges/xfor/pos_type.cc.h b/src/include/ranges/xfor/pos_type.cc.h index 0a596e6..4f1ab08 100644 --- a/src/include/ranges/xfor/pos_type.cc.h +++ b/src/include/ranges/xfor/pos_type.cc.h @@ -132,7 +132,7 @@ namespace CNORXZ } template - 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 + Arr SFPos::sMs = { Ms... }; + template constexpr SizeT SFPos::size() const { @@ -194,11 +197,9 @@ namespace CNORXZ } template - template constexpr auto SFPos::operator*(const UPos& a) const { - static const Arr ms({ Ms... }); - return FPos(N * a.val(), &ms[0]); + return FPos(N * a.val(), &sMs[0]); } template @@ -226,6 +227,14 @@ namespace CNORXZ "MPos has to be derived from scalar pos type"); } + template + constexpr MPos::MPos(const BPosT& b, const NPosT& n) : + BPosT(b), mNext(n) + { + static_assert(is_scalar_pos_type::value, + "MPos has to be derived from scalar pos type"); + } + template template constexpr MPos::MPos(Args&&... args, const NPosT& next) : @@ -251,7 +260,7 @@ namespace CNORXZ } template - constexpr const NPos& MPos::next() const + constexpr const NPosT& MPos::next() const { return mNext; } @@ -270,8 +279,8 @@ namespace CNORXZ constexpr auto MPos::operator*(const PosT& a) const { typedef decltype(BPosT::operator*(a)) OBPosT; - typedef decltype(mNext * a.next()) ONPosT; - return MPos( BPosT::operator*(a), mNext * a.next() ); + typedef decltype(mNext * a) ONPosT; + return MPos( BPosT::operator*(a), mNext * a ); } template @@ -279,8 +288,8 @@ namespace CNORXZ constexpr auto MPos::operator()(const PosT& a) const { typedef decltype(BPosT::operator()(a)) OBPosT; - typedef decltype(mNext(a.next())) ONPosT; - return MPos( BPosT::operator()(a), mNext(a.next()) ); + typedef decltype(mNext(a)) ONPosT; + return MPos( BPosT::operator()(a), mNext(a) ); } template diff --git a/src/include/ranges/xfor/pos_type.h b/src/include/ranges/xfor/pos_type.h index 827c45a..f839e97 100644 --- a/src/include/ranges/xfor/pos_type.h +++ b/src/include/ranges/xfor/pos_type.h @@ -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 class SFPos { + private: + static Arr sMs; public: constexpr SFPos() = default; @@ -123,8 +127,10 @@ namespace CNORXZ protected: NPosT mNext; public: - constexpr MPos() + constexpr MPos(); + constexpr MPos(const BPosT& b, const NPosT& n); + template 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 constexpr auto operator+(const PosT& a) const; diff --git a/src/tests/xfor_unit_test.cc b/src/tests/xfor_unit_test.cc index 426f5af..a78b76a 100644 --- a/src/tests/xfor_unit_test.cc +++ b/src/tests/xfor_unit_test.cc @@ -8,7 +8,7 @@ namespace using namespace CNORXZ; template - constexpr auto mkMPos(const CPosInterface& a, const CPosInterface& b) + constexpr auto mkMPos(const PosT1& a, const PosT2& b) { return MPos(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()); } /*