From a142fdb466daa73e30f68d76a919fee05d2ff24f Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Thu, 6 Oct 2022 18:32:56 +0200 Subject: [PATCH] im com --- src/include/ranges/xfor/pos_type.cc.h | 241 +++++++++++--------------- src/include/ranges/xfor/pos_type.h | 203 ++++++++-------------- 2 files changed, 166 insertions(+), 278 deletions(-) diff --git a/src/include/ranges/xfor/pos_type.cc.h b/src/include/ranges/xfor/pos_type.cc.h index 6d3a562..0a596e6 100644 --- a/src/include/ranges/xfor/pos_type.cc.h +++ b/src/include/ranges/xfor/pos_type.cc.h @@ -37,6 +37,13 @@ namespace CNORXZ return SPos(); } + template + template + constexpr auto SPos::operator()(const SPos& a) const + { + return SPos(); + } + template constexpr auto SPos::operator+(const UPos& a) const { @@ -49,9 +56,15 @@ namespace CNORXZ return UPos(N*a.val()); } + template + constexpr auto SPos::operator()(const UPos& a) const + { + return UPos(N*a.val()); + } + template template - constexpr auto SPos::extend(const CPosInterface& a) const + constexpr auto SPos::extend(const PosT& a) const { return MPos,PosT>(*this,a); } @@ -73,19 +86,25 @@ namespace CNORXZ } template - constexpr UPos UPos::operator+(const CPosInterface& in) const + constexpr UPos UPos::operator+(const PosT& in) const { return UPos(mExt + in.val()); } template - constexpr UPos UPos::operator*(const CPosInterface& in) const + constexpr UPos UPos::operator*(const PosT& in) const { return UPos(mExt * in.val()); } template - constexpr auto UPos::extend(const CPosInterface& p1) const + constexpr UPos UPos::operator()(const PosT& in) const + { + return UPos(mExt * in.val()); + } + + template + constexpr auto UPos::extend(const PosT& p1) const { return MPos(*this, p1); } @@ -107,19 +126,25 @@ namespace CNORXZ } template - constexpr UPos FPos::operator+(const CPosInterface& a) const + constexpr UPos FPos::operator+(const PosT1& a) const { return UPos(mExt + a.val()); } + template + constexpr FPos UPos::operator*(const PosT& in) const + { + return FPos(mExt * in.val(), mMap); + } + template - constexpr UPos FPos::operator*(const CPosInterface& a) const + constexpr UPos FPos::operator()(const PosT1& a) const { return UPos(mExt * mMap[a.val()]); } template - constexpr auto FPos::extend(const CPosInterface& a) const + constexpr auto FPos::extend(const PosT1& a) const { return MPos(*this,a); } @@ -150,6 +175,13 @@ namespace CNORXZ template template constexpr auto SFPos::operator*(const SPos& a) const + { + return SFPos(); + } + + template + template + constexpr auto SFPos::operator()(const SPos& a) const { constexpr Arr ms({ Ms... }); return SPos(ms)>(); @@ -162,7 +194,15 @@ namespace CNORXZ } template + template constexpr auto SFPos::operator*(const UPos& a) const + { + static const Arr ms({ Ms... }); + return FPos(N * a.val(), &ms[0]); + } + + template + constexpr auto SFPos::operator()(const UPos& a) const { constexpr Arr ms({ Ms... }); return UPos(N * ms[a.val()]); @@ -170,171 +210,84 @@ namespace CNORXZ template template - constexpr auto SFPos::extend(const CPosInterface& a) const + constexpr auto SFPos::extend(const PosT& a) const { return MPos,PosT>(*this,a); } - - /************ - * DPos * - ************/ - - inline DPos::DPos(Uptr&& a) : - ObjHandle(std::forward>(a)) - {} - - template - inline DPos::DPos(const CPosInterface& a) : - ObjHandle( std::make_unique>(a) ) - {} - - inline SizeT DPos::size() const - { - return mC->vsize(); - } - - inline SizeT DPos::val() const - { - return mC->vval(); - } - - inline DPosRef DPos::first() const - { - return DPosRef(mC->vget()); - } - - inline DPosRef DPos::next() const - { - return DPosRef(mC->vnext()); - } - - template - inline DPos DPos::operator+(const CPosInterface& a) const - { - VPosRef r(&a); - return DPos(mC->vplus(&r)); // check memory safety!!! - } - - template - inline DPos DPos::operator*(const CPosInterface& a) const - { - VPosRef r(&a); - return DPos(mC->vtimes(&r)); // check memory safety!!! - } - - template - inline DPos DPos::extend(const CPosInterface& a) const - { - return DPos(mC->vextend(a)); - } - - /*************** - * DPosRef * - ***************/ - - inline DPosRef::DPosRef(const VPosBase* c) : - mC(c) - {} - - inline SizeT DPosRef::size() const - { - return mC->vsize(); - } - - inline SizeT DPosRef::val() const - { - return mC->vval(); - } - - inline DPosRef DPosRef::first() const - { - return DPosRef(mC->vget()); - } - - inline DPosRef DPosRef::next() const - { - return DPosRef(mC->vnext()); - } - - template - inline DPos DPosRef::operator+(const CPosInterface& a) const - { - VPosRef r(&a); - return DPos(mC->vplus(&r)); // check memory safety!!! - } - - template - inline DPos DPosRef::operator*(const CPosInterface& a) const - { - VPosRef r(&a); - return DPos(mC->vtimes(&r)); // check memory safety!!! - } - - template - inline DPos DPosRef::extend(const CPosInterface& a) const - { - return DPos(mC->vextend(a)); - } - - /************ * MPos * ************/ - template - constexpr MPos::MPos(const CPosInterface& first, - const CPosInterface& next) : - mFirst(first.THIS()), mNext(next.THIS()) - {} - - template - constexpr SizeT MPos::size() const + template + constexpr MPos::MPos() { - return mFirst.size() + mNext.size(); + static_assert(is_scalar_pos_type::value, + "MPos has to be derived from scalar pos type"); } - template - constexpr auto MPos::val() const + template + template + constexpr MPos::MPos(Args&&... args, const NPosT& next) : + BPosT(args...), mNext(next) { - return mFirst.val(); + static_assert(is_scalar_pos_type::value, + "MPos has to be derived from scalar pos type"); } - template - constexpr const PosT1& MPos::first() const + template + template + constexpr MPos::MPos(Args&&... args, NPosT&& next) : + BPosT(args...), mNext(next) { - return mFirst; + static_assert(is_scalar_pos_type::value, + "MPos has to be derived from scalar pos type"); } - template - constexpr const PosT2& MPos::next() const + template + constexpr SizeT MPos::size() const + { + return BPosT::size() + mNext.size(); + } + + template + constexpr const NPos& MPos::next() const { return mNext; } - template - template - constexpr auto MPos::operator+(const MPos& a) const + template + template + constexpr auto MPos::operator+(const PosT& a) const { - typedef decltype(first()+a.first()) PosT5; - typedef decltype(next()+a.next()) PosT6; - return MPos(first()+a.first(), next()+a.next()); + typedef decltype(BPosT::operator+(a)) OBPosT; + typedef decltype(mNext + a.next()) ONPosT; + return MPos( BPosT::operator+(a), mNext + a.next() ); } - template - template - constexpr auto MPos::operator*(const CPosInterface& a) const + template + template + constexpr auto MPos::operator*(const PosT& a) const { - typedef decltype(first()*a.THIS()) PosT5; - typedef decltype(next()*a.THIS()) PosT6; - return MPos(first()*a.THIS(), next()*a.THIS()); + typedef decltype(BPosT::operator*(a)) OBPosT; + typedef decltype(mNext * a.next()) ONPosT; + return MPos( BPosT::operator*(a), mNext * a.next() ); } - template - template - constexpr auto MPos::extend(const CPosInterface& p) const + template + template + constexpr auto MPos::operator()(const PosT& a) const { - return MPos,PosT3>(*this,p); + typedef decltype(BPosT::operator()(a)) OBPosT; + typedef decltype(mNext(a.next())) ONPosT; + return MPos( BPosT::operator()(a), mNext(a.next()) ); + } + + template + template + constexpr auto MPos::extend(const PosT& a) const + { + return mNext.extend(a); } } diff --git a/src/include/ranges/xfor/pos_type.h b/src/include/ranges/xfor/pos_type.h index 5365bc6..827c45a 100644 --- a/src/include/ranges/xfor/pos_type.h +++ b/src/include/ranges/xfor/pos_type.h @@ -6,68 +6,45 @@ namespace CNORXZ { + // shift to base.h +#define CXZ_CVAL_FALSE static constexpr bool value = false +#define CXZ_CVAL_TRUE static constexpr bool value = true + + template + struct is_pos_type { CXZ_CVAL_FALSE; }; - template - class CPosInterface - { - public: - static constexpr bool MULTI = PosT::MULTI; - - DEFAULT_MEMBERS(CPosInterface); - - PosT& THIS() { return static_cast(*this); } - const PosT& THIS() const { return static_cast(*this); } - - inline SizeT size() const { return THIS().size(); } - inline auto val() const { return THIS().val(); } - // template!!! - inline CPosInterface operator+(const CPosInterface& a) const - { return THIS() + a.THIS(); } - // template!!! - inline CPosInterface operator*(const CPosInterface& a) const - { return THIS() * a.THIS(); } - // template!!! - // inline CPosInterface execute(const CPosInterface& a, - // const CPosInterface& b, const CPosInterface& c) const - // => a+b*c; only this executes also the FPos/SFPos-Map!!! - - // for each class implement +/* for each argument type EXPLICITLY (NO templates, except for MPos) - // *: only UPos/SPos as Arguments, for DPos only UPos as Args - - template - inline auto extend(const CPosInterface

& a) const { return THIS().extend(a); } - }; - + template + struct is_scalar_pos_type { CXZ_CVAL_FALSE; }; + template - class SPos : public CPosInterface> + class SPos { public: - static constexpr bool MULTI = false; - constexpr SPos() = default; constexpr SizeT size() const; constexpr SizeT val() const; - + template constexpr auto operator+(const SPos& a) const; template constexpr auto operator*(const SPos& a) const; + template + constexpr auto operator()(const SPos& a) const; constexpr auto operator+(const UPos& a) const; constexpr auto operator*(const UPos& a) const; - + constexpr auto operator()(const UPos& a) const; + template - constexpr auto extend(const CPosInterface& a) const; + constexpr auto extend(const PosT& a) const; }; - - class UPos : public CPosInterface + + class UPos { private: SizeT mExt = 0; public: - static constexpr bool MULTI = false; - DEFAULT_MEMBERS(UPos); constexpr UPos(SizeT ext); @@ -76,25 +53,26 @@ namespace CNORXZ constexpr const SizeT& val() const; template - constexpr UPos operator+(const CPosInterface& a) const; + constexpr UPos operator+(const PosT& a) const; template - constexpr UPos operator*(const CPosInterface& a) const; - + constexpr UPos operator*(const PosT& a) const; + + template + constexpr UPos operator()(const PosT& a) const; + template - constexpr auto extend(const CPosInterface& y) const; + constexpr auto extend(const PosT& a) const; }; - - class FPos : public CPosInterface + + class FPos { private: SizeT mExt = 0; const SizeT* mMap = nullptr; public: - static constexpr bool MULTI = false; - DEFAULT_MEMBERS(FPos); inline FPos(SizeT ext, const SizeT* map); @@ -103,21 +81,22 @@ namespace CNORXZ constexpr const SizeT& val() const; template - constexpr UPos operator+(const CPosInterface& a) const; + constexpr UPos operator+(const PosT1& a) const; template - constexpr UPos operator*(const CPosInterface& a) const; + constexpr FPos operator*(const PosT1& a) const; + + template + constexpr UPos operator()(const PosT& a) const; template - constexpr auto extend(const CPosInterface& a) const; + constexpr auto extend(const PosT1& a) const; }; template - class SFPos : public CPosInterface> + class SFPos { public: - static constexpr bool MULTI = false; - constexpr SFPos() = default; constexpr SizeT size() const; @@ -127,101 +106,57 @@ namespace CNORXZ constexpr auto operator+(const SPos& a) const; template constexpr auto operator*(const SPos& a) const; + template + constexpr auto operator()(const SPos& a) const; constexpr auto operator+(const UPos& a) const; constexpr auto operator*(const UPos& a) const; + constexpr auto operator()(const UPos& a) const; template - constexpr auto extend(const CPosInterface& a) const; - }; - - class DPos : public ObjHandle, - public CPosInterface - { - public: - static constexpr bool MULTI = true; - - DEFAULT_MEMBERS(DPos); - inline DPos(Uptr&& a); - - template - inline DPos(const CPosInterface& a); - - inline SizeT size() const; - inline SizeT val() const; - inline DPosRef first() const; - inline DPosRef next() const; - - template - inline DPos operator+(const CPosInterface& a) const; - - template - inline DPos operator*(const CPosInterface& a) const; - - template - inline DPos extend(const CPosInterface& a) const; - - }; - - class DPosRef : public CPosInterface - { - private: - const VPosBase* mC; - public: - static constexpr bool MULTI = true; - - DEFAULT_MEMBERS(DPosRef); - inline DPosRef(const VPosBase* c); - - inline SizeT size() const; - inline SizeT val() const; - inline DPosRef first() const; - inline DPosRef next() const; - - template - inline DPos operator+(const CPosInterface& a) const; - - template - inline DPos operator*(const CPosInterface& a) const; - - template - inline DPos extend(const CPosInterface& a) const; + constexpr auto extend(const PosT& a) const; }; - // go to original pattern (-> LINEAR template chain) - // first: just cast by constructor - template - class MPos : public CPosInterface> + template + class MPos : public BPosT // BPos should be a SCALAR PosT (NO MPos!) { - private: - - PosT1 mFirst; - PosT2 mNext; - + protected: + NPosT mNext; public: - static constexpr bool MULTI = true; + constexpr MPos() - DEFAULT_MEMBERS(MPos); - - constexpr MPos(const CPosInterface& first, - const CPosInterface& next); + template + constexpr MPos(Args&&... args, const NPosT& next); + + template + constexpr MPos(Args&&... args, NPosT&& next); constexpr SizeT size() const; - constexpr auto val() const; - constexpr const PosT1& first() const; - constexpr const PosT2& next() const; + constexpr const NPos& next() const; - template - constexpr auto operator+(const MPos& a) const; + template + constexpr auto operator+(const PosT& a) const; - template - constexpr auto operator*(const CPosInterface& a) const; + template + constexpr auto operator*(const PosT& a) const; - template - constexpr auto extend(const CPosInterface& p) const; + // same as operator*, except for FPos/SFPos, where map is executed + template + constexpr auto operator()(const PosT& a) const; + + template + constexpr auto extend(const PosT& a) const; + }; - }; - + template struct is_pos_type> { CXZ_CVAL_TRUE; }; + template struct is_scalar_pos_type> { CXZ_CVAL_TRUE; }; + template <> struct is_pos_type { CXZ_CVAL_TRUE; }; + template <> struct is_scalar_pos_type { CXZ_CVAL_TRUE; }; + template <> struct is_pos_type { CXZ_CVAL_TRUE; }; + template <> struct is_scalar_pos_type { CXZ_CVAL_TRUE; }; + template struct is_pos_type> { CXZ_CVAL_TRUE; }; + template struct is_scalar_pos_type> { CXZ_CVAL_TRUE; }; + template struct is_pos_type> { CXZ_CVAL_TRUE; }; } // end namespace CNORXZInternal