From ee3e1b5d4f036c17af970a7884b9f70eb63d72b5 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Sun, 27 Oct 2024 00:47:53 -0700 Subject: [PATCH] various improvements regarding static pos evaluation --- src/include/ranges/lindex.cc.h | 8 +++++++- src/include/ranges/srange.h | 16 ++++++++++++++++ src/include/xpr/pos_type.cc.h | 10 ++++++++-- src/include/xpr/pos_type.h | 1 + 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/include/ranges/lindex.cc.h b/src/include/ranges/lindex.cc.h index 5ec5342..173ed19 100644 --- a/src/include/ranges/lindex.cc.h +++ b/src/include/ranges/lindex.cc.h @@ -49,7 +49,13 @@ namespace CNORXZ template decltype(auto) LIndex::ifor(const Xpr& xpr, F&& f) const { - return For(this->pmax().val(), this->id(), xpr, std::forward(f)); + if constexpr(index_has_const_size::value){ + constexpr SizeT S = index_const_size::value; + return SFor(this->id(), xpr, std::forward(f)); + } + else { + return For(this->pmax().val(), this->id(), xpr, std::forward(f)); + } } template diff --git a/src/include/ranges/srange.h b/src/include/ranges/srange.h index dc7598f..d03f502 100644 --- a/src/include/ranges/srange.h +++ b/src/include/ranges/srange.h @@ -247,6 +247,22 @@ namespace CNORXZ { static constexpr bool value = true; }; + + /** *** + SIndex has static range size + @see index_expression_exists + */ + template + struct index_has_const_size> + { static constexpr bool value = true; }; + + /** *** + SIndex has static range size + @see index_expression_exists + */ + template + struct index_const_size> + { static constexpr SizeT value = S; }; } #endif diff --git a/src/include/xpr/pos_type.cc.h b/src/include/xpr/pos_type.cc.h index 2837adb..32b3fc3 100644 --- a/src/include/xpr/pos_type.cc.h +++ b/src/include/xpr/pos_type.cc.h @@ -480,13 +480,19 @@ namespace CNORXZ return mNext; } + template + constexpr const BPosT& MPos::bpos() const + { + return *this; + } + template template constexpr decltype(auto) MPos::operator+(const PosT& a) const { - typedef decltype(BPosT::operator+(a)) OBPosT; + typedef decltype(BPosT::operator+(a.bpos())) OBPosT; typedef decltype(mNext + a.next()) ONPosT; - return MPos( BPosT::operator+(a), mNext + a.next() ); + return MPos( BPosT::operator+(a.bpos()), mNext + a.next() ); } template diff --git a/src/include/xpr/pos_type.h b/src/include/xpr/pos_type.h index 14505d1..99597ef 100644 --- a/src/include/xpr/pos_type.h +++ b/src/include/xpr/pos_type.h @@ -177,6 +177,7 @@ namespace CNORXZ constexpr SizeT size() const; constexpr const NPosT& next() const; + constexpr const BPosT& bpos() const; template constexpr decltype(auto) operator+(const PosT& a) const;