new DPos/VPos + further macros

This commit is contained in:
Christian Zimmermann 2022-10-11 18:36:23 +02:00
parent ee1fe52429
commit ed6c90b95c
8 changed files with 303 additions and 94 deletions

View file

@ -19,8 +19,20 @@
#define DEFAULT_MOVE_A(__class_name__) __class_name__& operator=(__class_name__&& a) = default #define DEFAULT_MOVE_A(__class_name__) __class_name__& operator=(__class_name__&& a) = default
#define DEFAULT_COPY(__class_name__) DEFAULT_COPY_C(__class_name__); DEFAULT_COPY_A(__class_name__) #define DEFAULT_COPY(__class_name__) DEFAULT_COPY_C(__class_name__); DEFAULT_COPY_A(__class_name__)
#define DEFAULT_MOVE(__class_name__) DEFAULT_MOVE_C(__class_name__); DEFAULT_MOVE_A(__class_name__) #define DEFAULT_MOVE(__class_name__) DEFAULT_MOVE_C(__class_name__); DEFAULT_MOVE_A(__class_name__)
#define DEFAULT_MEMBERS_X(__class_name__) DEFAULT_COPY(__class_name__); DEFAULT_MOVE(__class_name__) #define DEFAULT_MEMBERS_X(__class_name__) DEFAULT_COPY(__class_name__); DEFAULT_MOVE(__class_name__)
#define DEFAULT_MEMBERS(__class_name__) DEFAULT_C(__class_name__); DEFAULT_MEMBERS_X(__class_name__) #define DEFAULT_MEMBERS(__class_name__) DEFAULT_C(__class_name__); DEFAULT_MEMBERS_X(__class_name__)
#define SP_DEFAULT_C(__spec__,__class_name__) __spec__ __class_name__() = default
#define SP_DEFAULT_COPY_C(__spec__,__class_name__) __spec__ __class_name__(const __class_name__& a) = default
#define SP_DEFAULT_COPY_A(__spec__,__class_name__) __spec__ __class_name__& operator=(const __class_name__& a) = default
#define SP_DEFAULT_MOVE_C(__spec__,__class_name__) __spec__ __class_name__(__class_name__&& a) = default
#define SP_DEFAULT_MOVE_A(__spec__,__class_name__) __spec__ __class_name__& operator=(__class_name__&& a) = default
#define SP_DEFAULT_COPY(__spec__,__class_name__) SP_DEFAULT_COPY_C(__spec__,__class_name__); SP_DEFAULT_COPY_A(__spec__,__class_name__)
#define SP_DEFAULT_MOVE(__spec__,__class_name__) SP_DEFAULT_MOVE_C(__spec__,__class_name__); SP_DEFAULT_MOVE_A(__spec__,__class_name__)
#define SP_DEFAULT_MEMBERS_X(__spec__,__class_name__) SP_DEFAULT_COPY(__spec__,__class_name__); SP_DEFAULT_MOVE(__spec__,__class_name__)
#define SP_DEFAULT_MEMBERS(__spec__,__class_name__) SP_DEFAULT_C(__spec__,__class_name__); SP_DEFAULT_MEMBERS_X(__spec__,__class_name__)
#define CXZ_CVAL_FALSE static constexpr bool value = false
#define CXZ_CVAL_TRUE static constexpr bool value = true
#endif #endif

View file

@ -10,9 +10,6 @@ namespace CNORXZ
template <typename T> template <typename T>
ObjHandle<T>::ObjHandle() {} ObjHandle<T>::ObjHandle() {}
template <typename T>
ObjHandle<T>::ObjHandle(const T& a) : mC(std::make_unique<T>(a)) {}
template <typename T> template <typename T>
ObjHandle<T>::ObjHandle(Uptr<T>&& a) : mC(std::forward<Uptr<T>>(a)) {} ObjHandle<T>::ObjHandle(Uptr<T>&& a) : mC(std::forward<Uptr<T>>(a)) {}

View file

@ -18,7 +18,6 @@ namespace CNORXZ
public: public:
ObjHandle(); ObjHandle();
ObjHandle(const T& a);
ObjHandle(Uptr<T>&& a); ObjHandle(Uptr<T>&& a);
ObjHandle(const ObjHandle& a); ObjHandle(const ObjHandle& a);
ObjHandle(ObjHandle&& a); ObjHandle(ObjHandle&& a);

View file

@ -120,16 +120,6 @@ namespace CNORXZ
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
class MPos; class MPos;
// definition: ranges/xfor/pos_type.h
template <class PosT>
class FMPos;
// definition: ranges/xfor/pos_type.h
class UPos;
// definition: ranges/xfor/pos_type.h
class FPos;
// definition: ranges/range_base.h // definition: ranges/range_base.h
class RangeBase; class RangeBase;

View file

@ -216,6 +216,12 @@ namespace CNORXZ
return MPos<SFPos<N,Ms...>,PosT>(*this,a); return MPos<SFPos<N,Ms...>,PosT>(*this,a);
} }
template <SizeT N, SizeT... Ms>
constexpr SFPos<N,Ms...>::operator FPos() const
{
return FPos(N, &sMs[0]);
}
/************ /************
* MPos * * MPos *
************/ ************/
@ -299,6 +305,117 @@ namespace CNORXZ
return mNext.extend(a); return mNext.extend(a);
} }
/************
* DPos *
************/
inline DPos::DPos(Uptr<VPosBase>&& a) :
ObjHandle<VPosBase>(std::forward<Uptr<VPosBase>>(a))
{}
template <class PosT>
inline DPos::DPos(const PosT& a) :
ObjHandle<VPosBase>(std::make_unique<VPos<PosT>>(a))
{
static_assert(is_pos_type<PosT>::value,
"DPos can only be constructed from pos types");
}
template <class PosT>
inline DPos::DPos(PosT&& a) :
ObjHandle<VPosBase>(std::make_unique<VPos<PosT>>(a))
{
static_assert(is_pos_type<PosT>::value,
"DPos can only be constructed from pos types");
}
inline SizeT DPos::size() const
{
return mC->vsize();
}
inline SizeT DPos::val() const
{
return mC->vval();
}
inline DPosRef DPos::next() const
{
return DPosRef(mC->vnext());
}
template <class PosT>
inline DPos DPos::operator+(const PosT& a) const
{
return DPos(mC->vplus( VPosRef<PosT>(&a) ));
}
template <class PosT>
inline DPos DPos::operator*(const PosT& a) const
{
return DPos(mC->vtimes( VPosRef<PosT>(&a) ));
}
// same as operator*, except for FPos/SFPos, where map is executed
template <class PosT>
inline DPos DPos::operator()(const PosT& a) const
{
return DPos(mC->vexec( VPosRef<PosT>(&a) ));
}
template <class PosT>
inline DPos DPos::extend(const PosT& a) const
{
return DPos(mC->vextend( a ));
}
/***************
* DPosRef *
***************/
inline DPosRef::DPosRef(const VPosBase* p) : mP(p) {}
inline SizeT DPosRef::size() const
{
return mP->vsize();
}
inline SizeT DPosRef::val() const
{
return mP->vval();
}
inline DPosRef DPosRef::next() const
{
return DPosRef(mP->vnext());
}
template <class PosT>
inline DPos DPosRef::operator+(const PosT& a) const
{
return DPos(mP->vplus( VPosRef<PosT>(&a) ));
}
template <class PosT>
inline DPos DPosRef::operator*(const PosT& a) const
{
return DPos(mP->vtimes( VPosRef<PosT>(&a) ));
}
// same as operator*, except for FPos/SFPos, where map is executed
template <class PosT>
inline DPos DPosRef::operator()(const PosT& a) const
{
return DPos(mP->vexec( VPosRef<PosT>(&a) ));
}
template <class PosT>
inline DPos DPosRef::extend(const PosT& a) const
{
return DPos(mP->vextend( a ));
}
} }
#endif #endif

View file

@ -6,9 +6,6 @@
namespace CNORXZ 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 <class T> template <class T>
struct is_pos_type { CXZ_CVAL_FALSE; }; struct is_pos_type { CXZ_CVAL_FALSE; };
@ -93,6 +90,7 @@ namespace CNORXZ
template <class PosT1> template <class PosT1>
constexpr auto extend(const PosT1& a) const; constexpr auto extend(const PosT1& a) const;
}; };
template <SizeT N, SizeT... Ms> template <SizeT N, SizeT... Ms>
@ -119,6 +117,8 @@ namespace CNORXZ
template <class PosT> template <class PosT>
constexpr auto extend(const PosT& a) const; constexpr auto extend(const PosT& a) const;
explicit constexpr operator FPos() const;
}; };
template <class BPosT, class NPosT> template <class BPosT, class NPosT>
@ -154,6 +154,65 @@ namespace CNORXZ
constexpr auto extend(const PosT& a) const; constexpr auto extend(const PosT& a) const;
}; };
class DPos : public ObjHandle<VPosBase>
{
public:
DEFAULT_MEMBERS(DPos);
inline DPos(Uptr<VPosBase>&& a);
template <class PosT>
inline explicit DPos(const PosT& a);
template <class PosT>
inline explicit DPos(PosT&& a);
inline SizeT size() const;
inline SizeT val() const;
inline DPosRef next() const;
template <class PosT>
inline DPos operator+(const PosT& a) const;
template <class PosT>
inline DPos operator*(const PosT& a) const;
// same as operator*, except for FPos/SFPos, where map is executed
template <class PosT>
inline DPos operator()(const PosT& a) const;
template <class PosT>
inline DPos extend(const PosT& a) const;
};
class DPosRef
{
private:
const VPosBase* mP = nullptr;
public:
DEFAULT_MEMBERS(DPosRef);
explicit DPosRef(const VPosBase* p);
inline SizeT size() const;
inline SizeT val() const;
inline DPosRef next() const;
template <class PosT>
inline DPos operator+(const PosT& a) const;
template <class PosT>
inline DPos operator*(const PosT& a) const;
// same as operator*, except for FPos/SFPos, where map is executed
template <class PosT>
inline DPos operator()(const PosT& a) const;
template <class PosT>
inline DPos extend(const PosT& a) const;
};
template <SizeT N> struct is_pos_type<SPos<N>> { CXZ_CVAL_TRUE; }; template <SizeT N> struct is_pos_type<SPos<N>> { CXZ_CVAL_TRUE; };
template <SizeT N> struct is_scalar_pos_type<SPos<N>> { CXZ_CVAL_TRUE; }; template <SizeT N> struct is_scalar_pos_type<SPos<N>> { CXZ_CVAL_TRUE; };
template <> struct is_pos_type<UPos> { CXZ_CVAL_TRUE; }; template <> struct is_pos_type<UPos> { CXZ_CVAL_TRUE; };
@ -163,6 +222,8 @@ namespace CNORXZ
template <SizeT N, SizeT... Ms> struct is_pos_type<SFPos<N,Ms...>> { CXZ_CVAL_TRUE; }; template <SizeT N, SizeT... Ms> struct is_pos_type<SFPos<N,Ms...>> { CXZ_CVAL_TRUE; };
template <SizeT N, SizeT... Ms> struct is_scalar_pos_type<SFPos<N,Ms...>> { CXZ_CVAL_TRUE; }; template <SizeT N, SizeT... Ms> struct is_scalar_pos_type<SFPos<N,Ms...>> { CXZ_CVAL_TRUE; };
template <class BPosT, class NPosT> struct is_pos_type<MPos<BPosT,NPosT>> { CXZ_CVAL_TRUE; }; template <class BPosT, class NPosT> struct is_pos_type<MPos<BPosT,NPosT>> { CXZ_CVAL_TRUE; };
template <> struct is_pos_type<DPos> { CXZ_CVAL_TRUE; };
template <> struct is_pos_type<DPosRef> { CXZ_CVAL_TRUE; };
} // end namespace CNORXZInternal } // end namespace CNORXZInternal

View file

@ -16,13 +16,19 @@ namespace CNORXZ
return this->vextend(UPos(N)); return this->vextend(UPos(N));
} }
template <SizeT N, SizeT... Ms>
Uptr<VPosBase> VPosBase::vextend(const SFPos<N,Ms...>& a) const
{
return this->vextend(static_cast<FPos>(a));
}
/************ /************
* VPos * * VPos *
************/ ************/
template <class PosT> template <class PosT>
VPos<PosT>::VPos(const CPosInterface<PosT>& a) : VPos<PosT>::VPos(const PosT& a) :
PosT(a.THIS()) PosT(a)
{} {}
template <class PosT> template <class PosT>
@ -43,12 +49,6 @@ namespace CNORXZ
return PosT::THIS().val(); return PosT::THIS().val();
} }
template <class PosT>
const VPosBase* VPos<PosT>::vget() const
{
return this;
}
template <class PosT> template <class PosT>
const VPosBase* VPos<PosT>::vnext() const const VPosBase* VPos<PosT>::vnext() const
{ {
@ -58,37 +58,50 @@ namespace CNORXZ
template <class PosT> template <class PosT>
Uptr<VPosBase> VPos<PosT>::vplus(const VPosBase* a) const Uptr<VPosBase> VPos<PosT>::vplus(const VPosBase* a) const
{ {
return std::make_unique<VPos<PosT>>((*this) + DPosRef(a)); typedef decltype((*this) + UPos(a->vval())) OPosT;
return std::make_unique<VPos<OPosT>>((*this) + UPos(a->vval()));
} }
template <class PosT> template <class PosT>
Uptr<VPosBase> VPos<PosT>::vtimes(const VPosBase* a) const Uptr<VPosBase> VPos<PosT>::vtimes(const VPosBase* a) const
{ {
return std::make_unique<VPos<PosT>>((*this) * UPos(a->vval())); typedef decltype((*this) * UPos(a->vval())) OPosT;
return std::make_unique<VPos<OPosT>>((*this) * UPos(a->vval()));
}
template <class PosT>
Uptr<VPosBase> VPos<PosT>::vexec(const VPosBase* a) const
{
typedef decltype((*this)(UPos(a->vval()))) OPosT;
return std::make_unique<VPos<OPosT>>( (*this)(UPos(a->vval())) );
} }
template <class PosT> template <class PosT>
Uptr<VPosBase> VPos<PosT>::vextend(const DPos& a) const Uptr<VPosBase> VPos<PosT>::vextend(const DPos& a) const
{ {
return std::make_unique<MPos<PosT,DPos>>(*this,a); typedef decltype(this->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(this->extend(a));
} }
template <class PosT> template <class PosT>
Uptr<VPosBase> VPos<PosT>::vextend(const DPosRef& a) const Uptr<VPosBase> VPos<PosT>::vextend(const DPosRef& a) const
{ {
return std::make_unique<MPos<PosT,DPosRef>>(*this,a); typedef decltype(this->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(this->extend(a));
} }
template <class PosT> template <class PosT>
Uptr<VPosBase> VPos<PosT>::vextend(const UPos& a) const Uptr<VPosBase> VPos<PosT>::vextend(const UPos& a) const
{ {
return std::make_unique<MPos<PosT,UPos>>(*this,a); typedef decltype(this->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(this->extend(a));
} }
template <class PosT> template <class PosT>
Uptr<VPosBase> VPos<PosT>::vextend(const FPos& a) const Uptr<VPosBase> VPos<PosT>::vextend(const FPos& a) const
{ {
return std::make_unique<MPos<PosT,FPos>>(*this,a); typedef decltype(this->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(this->extend(a));
} }
// .... probably I need to define a static instanciation limit... // .... probably I need to define a static instanciation limit...
@ -97,9 +110,9 @@ namespace CNORXZ
******************/ ******************/
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
VPos<MPos<PosT1,PosT2>>::VPos(const CPosInterface<MPos<PosT1,PosT2>>& a) : VPos<MPos<PosT1,PosT2>>::VPos(const MPos<PosT1,PosT2>& a) :
MPos<PosT1,PosT2>(a.THIS()), MPos<PosT1,PosT2>(a.THIS()),
mFRef(&this->first()), mNRef(&this->next()) mNRef(&this->next())
{} {}
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
@ -120,12 +133,6 @@ namespace CNORXZ
return this->val(); return this->val();
} }
template <class PosT1, class PosT2>
const VPosBase* VPos<MPos<PosT1,PosT2>>::vget() const
{
return &mFRef;
}
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
const VPosBase* VPos<MPos<PosT1,PosT2>>::vnext() const const VPosBase* VPos<MPos<PosT1,PosT2>>::vnext() const
{ {
@ -135,37 +142,50 @@ namespace CNORXZ
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vplus(const VPosBase* a) const Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vplus(const VPosBase* a) const
{ {
return std::make_unique<MPos<PosT1,PosT2>>((*this) + DPosRef(a)); typedef decltype((*this) + DPosRef(a)) OPosT;
return std::make_unique<VPos<OPosT>>((*this) + DPosRef(a));
} }
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vtimes(const VPosBase* a) const Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vtimes(const VPosBase* a) const
{ {
return std::make_unique<MPos<PosT1,PosT2>>((*this) * UPos(a->vval())); typedef decltype((*this) * UPos(a->vval())) OPosT;
return std::make_unique<VPos<OPosT>>((*this) * UPos(a->vval()));
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vexec(const VPosBase* a) const
{
typedef decltype( (*this)(UPos(a->vval())) ) OPosT;
return std::make_unique<VPos<OPosT>>( (*this)(UPos(a->vval())) );
} }
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vextend(const DPos& a) const Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vextend(const DPos& a) const
{ {
return std::make_unique<MPos<MPosT,DPos>>(*this,a); typedef decltype(this->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(this->extend(a));
} }
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vextend(const DPosRef& a) const Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vextend(const DPosRef& a) const
{ {
return std::make_unique<MPos<MPosT,DPosRef>>(*this,a); typedef decltype(this->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(this->extend(a));
} }
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vextend(const UPos& a) const Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vextend(const UPos& a) const
{ {
return std::make_unique<MPos<MPosT,UPos>>(*this,a); typedef decltype(this->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(this->extend(a));
} }
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vextend(const FPos& a) const Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vextend(const FPos& a) const
{ {
return std::make_unique<MPos<MPosT,FPos>>(*this,a); typedef decltype(this->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(this->extend(a));
} }
/*************** /***************
@ -173,8 +193,8 @@ namespace CNORXZ
***************/ ***************/
template <class PosT> template <class PosT>
VPosRef<PosT>::VPosRef(const CPosInterface<PosT>* c) : VPosRef<PosT>::VPosRef(const PosT* c) :
mC(&c->THIS()) mC(&c)
{} {}
template <class PosT> template <class PosT>
@ -195,12 +215,6 @@ namespace CNORXZ
return mC->val(); return mC->val();
} }
template <class PosT>
const VPosBase* VPosRef<PosT>::vget() const
{
return this;
}
template <class PosT> template <class PosT>
const VPosBase* VPosRef<PosT>::vnext() const const VPosBase* VPosRef<PosT>::vnext() const
{ {
@ -210,37 +224,50 @@ namespace CNORXZ
template <class PosT> template <class PosT>
Uptr<VPosBase> VPosRef<PosT>::vplus(const VPosBase* a) const Uptr<VPosBase> VPosRef<PosT>::vplus(const VPosBase* a) const
{ {
return std::make_unique<VPos<PosT>>((*mC) + DPosRef(a)); typedef decltype((*mC) + UPos(a->vval())) OPosT;
return std::make_unique<VPos<OPosT>>((*mC) + UPos(a->vval()));
} }
template <class PosT> template <class PosT>
Uptr<VPosBase> VPosRef<PosT>::vtimes(const VPosBase* a) const Uptr<VPosBase> VPosRef<PosT>::vtimes(const VPosBase* a) const
{ {
return std::make_unique<VPos<PosT>>((*mC) * UPos(a->vval())); typedef decltype((*mC) * UPos(a->vval())) OPosT;
return std::make_unique<VPos<OPosT>>((*mC) * UPos(a->vval()));
}
template <class PosT>
Uptr<VPosBase> VPosRef<PosT>::vexec(const VPosBase* a) const
{
typedef decltype( (*mC)(UPos(a->vval())) ) OPosT;
return std::make_unique<VPos<OPosT>>( (*mC)(UPos(a->vval())) );
} }
template <class PosT> template <class PosT>
Uptr<VPosBase> VPosRef<PosT>::vextend(const DPos& a) const Uptr<VPosBase> VPosRef<PosT>::vextend(const DPos& a) const
{ {
return std::make_unique<MPos<PosT,DPos>>(*mC,a); typedef decltype(mC->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(mC->extend(a));
} }
template <class PosT> template <class PosT>
Uptr<VPosBase> VPosRef<PosT>::vextend(const DPosRef& a) const Uptr<VPosBase> VPosRef<PosT>::vextend(const DPosRef& a) const
{ {
return std::make_unique<MPos<PosT,DPosRef>>(*mC,a); typedef decltype(mC->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(mC->extend(a));
} }
template <class PosT> template <class PosT>
Uptr<VPosBase> VPosRef<PosT>::vextend(const UPos& a) const Uptr<VPosBase> VPosRef<PosT>::vextend(const UPos& a) const
{ {
return std::make_unique<MPos<PosT,UPos>>(*mC,a); typedef decltype(mC->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(mC->extend(a));
} }
template <class PosT> template <class PosT>
Uptr<VPosBase> VPosRef<PosT>::vextend(const FPos& a) const Uptr<VPosBase> VPosRef<PosT>::vextend(const FPos& a) const
{ {
return std::make_unique<MPos<PosT,FPos>>(*mC,a); typedef decltype(mC->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(mC->extend(a));
} }
/********************* /*********************
@ -248,14 +275,14 @@ namespace CNORXZ
*********************/ *********************/
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
VPosRef<MPos<PosT1,PosT2>>::VPosRef(const CPosInterface<MPos<PosT1,PosT2>>* c) : VPosRef<MPos<PosT1,PosT2>>::VPosRef(const MPos<PosT1,PosT2>* c) :
mC(c), mFRef(&c->get()), mNRef(&c->next()) mC(c), mNRef(&c->next())
{} {}
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::copy() const Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::copy() const
{ {
return std::make_unique<VPos<MPos<PosT1,PosT2>>>(*mFRef,*mNRef); return std::make_unique<VPos<MPos<PosT1,PosT2>>>(*mC);
} }
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
@ -270,12 +297,6 @@ namespace CNORXZ
return mC->val(); return mC->val();
} }
template <class PosT1, class PosT2>
const VPosBase* VPosRef<MPos<PosT1,PosT2>>::vget() const
{
return mFRef;
}
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
const VPosBase* VPosRef<MPos<PosT1,PosT2>>::vnext() const const VPosBase* VPosRef<MPos<PosT1,PosT2>>::vnext() const
{ {
@ -285,37 +306,50 @@ namespace CNORXZ
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vplus(const VPosBase* a) const Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vplus(const VPosBase* a) const
{ {
return std::make_unique<MPos<PosT1,PosT2>>((*mC) + DPosRef(a)); typedef decltype((*mC) + DPosRef(a)) OPosT;
return std::make_unique<VPos<OPosT>>((*mC) + DPosRef(a));
} }
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vtimes(const VPosBase* a) const Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vtimes(const VPosBase* a) const
{ {
return std::make_unique<MPos<PosT1,PosT2>>((*mC) * UPos(a->vval())); typedef decltype((*mC) * UPos(a->vval())) OPosT;
return std::make_unique<VPos<OPosT>>((*mC) * UPos(a->vval()));
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vexec(const VPosBase* a) const
{
typedef decltype( (*mC)(UPos(a->vval())) ) OPosT;
return std::make_unique<VPos<OPosT>>( (*mC)(UPos(a->vval())) );
} }
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vextend(const DPos& a) const Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vextend(const DPos& a) const
{ {
return std::make_unique<MPos<MPosT,DPos>>(*mC,a); typedef decltype(mC->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(mC->extend(a));
} }
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vextend(const DPosRef& a) const Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vextend(const DPosRef& a) const
{ {
return std::make_unique<MPos<MPosT,DPosRef>>(*mC,a); typedef decltype(mC->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(mC->extend(a));
} }
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vextend(const UPos& a) const Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vextend(const UPos& a) const
{ {
return std::make_unique<MPos<MPosT,UPos>>(*mC,a); typedef decltype(mC->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(mC->extend(a));
} }
template <class PosT1, class PosT2> template <class PosT1, class PosT2>
Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vextend(const FPos& a) const Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vextend(const FPos& a) const
{ {
return std::make_unique<MPos<MPosT,FPos>>(*mC,a); typedef decltype(mC->extend(a)) OPosT;
return std::make_unique<VPos<OPosT>>(mC->extend(a));
} }
} }

View file

@ -14,10 +14,10 @@ namespace CNORXZ
virtual Uptr<VPosBase> copy() const = 0; virtual Uptr<VPosBase> copy() const = 0;
virtual SizeT vsize() const = 0; virtual SizeT vsize() const = 0;
virtual SizeT vval() const = 0; virtual SizeT vval() const = 0;
virtual const VPosBase* vget() const = 0;
virtual const VPosBase* vnext() const = 0; virtual const VPosBase* vnext() const = 0;
virtual Uptr<VPosBase> vplus(const VPosBase* a) const = 0; virtual Uptr<VPosBase> vplus(const VPosBase* a) const = 0;
virtual Uptr<VPosBase> vtimes(const VPosBase* a) const = 0; virtual Uptr<VPosBase> vtimes(const VPosBase* a) const = 0;
virtual Uptr<VPosBase> vexec(const VPosBase* a) const = 0;
virtual Uptr<VPosBase> vextend(const DPos& a) const = 0; virtual Uptr<VPosBase> vextend(const DPos& a) const = 0;
virtual Uptr<VPosBase> vextend(const DPosRef& a) const = 0; virtual Uptr<VPosBase> vextend(const DPosRef& a) const = 0;
virtual Uptr<VPosBase> vextend(const UPos& a) const = 0; virtual Uptr<VPosBase> vextend(const UPos& a) const = 0;
@ -25,6 +25,9 @@ namespace CNORXZ
template <SizeT N> template <SizeT N>
Uptr<VPosBase> vextend(const SPos<N>& a) const; Uptr<VPosBase> vextend(const SPos<N>& a) const;
template <SizeT N, SizeT... Ms>
Uptr<VPosBase> vextend(const SFPos<N,Ms...>& a) const;
}; };
template <class PosT> template <class PosT>
@ -33,15 +36,15 @@ namespace CNORXZ
public: public:
DEFAULT_MEMBERS(VPos); DEFAULT_MEMBERS(VPos);
VPos(const CPosInterface<PosT>& a); VPos(const PosT& a);
virtual Uptr<VPosBase> copy() const override final; virtual Uptr<VPosBase> copy() const override final;
virtual SizeT vsize() const override final; virtual SizeT vsize() const override final;
virtual SizeT vval() const override final; virtual SizeT vval() const override final;
virtual const VPosBase* vget() const override final;
virtual const VPosBase* vnext() const override final; virtual const VPosBase* vnext() const override final;
virtual Uptr<VPosBase> vplus(const VPosBase* a) const override final; virtual Uptr<VPosBase> vplus(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vtimes(const VPosBase* a) const override final; virtual Uptr<VPosBase> vtimes(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vexec(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vextend(const DPos& a) const override final; virtual Uptr<VPosBase> vextend(const DPos& a) const override final;
virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final; virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final;
virtual Uptr<VPosBase> vextend(const UPos& a) const override final; virtual Uptr<VPosBase> vextend(const UPos& a) const override final;
@ -52,21 +55,19 @@ namespace CNORXZ
class VPos<MPos<PosT1,PosT2>> : public VPosBase, public MPos<PosT1,PosT2> class VPos<MPos<PosT1,PosT2>> : public VPosBase, public MPos<PosT1,PosT2>
{ {
private: private:
VPosRef<PosT1> mFRef;
VPosRef<PosT2> mNRef; VPosRef<PosT2> mNRef;
public:
typedef MPos<PosT1,PosT2> MPosT;
public:
DEFAULT_MEMBERS(VPos); DEFAULT_MEMBERS(VPos);
VPos(const CPosInterface<MPos<PosT1,PosT2>>& a); VPos(const MPos<PosT1,PosT2>& a);
virtual Uptr<VPosBase> copy() const override final; virtual Uptr<VPosBase> copy() const override final;
virtual SizeT vsize() const override final; virtual SizeT vsize() const override final;
virtual SizeT vval() const override final; virtual SizeT vval() const override final;
virtual const VPosBase* vget() const override final;
virtual const VPosBase* vnext() const override final; virtual const VPosBase* vnext() const override final;
virtual Uptr<VPosBase> vplus(const VPosBase* a) const override final; virtual Uptr<VPosBase> vplus(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vtimes(const VPosBase* a) const override final; virtual Uptr<VPosBase> vtimes(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vexec(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vextend(const DPos& a) const override final; virtual Uptr<VPosBase> vextend(const DPos& a) const override final;
virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final; virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final;
virtual Uptr<VPosBase> vextend(const UPos& a) const override final; virtual Uptr<VPosBase> vextend(const UPos& a) const override final;
@ -81,15 +82,15 @@ namespace CNORXZ
public: public:
DEFAULT_MEMBERS(VPosRef); DEFAULT_MEMBERS(VPosRef);
VPosRef(const CPosInterface<PosT>* c); VPosRef(const PosT* c);
virtual Uptr<VPosBase> copy() const override final; virtual Uptr<VPosBase> copy() const override final;
virtual SizeT vsize() const override final; virtual SizeT vsize() const override final;
virtual SizeT vval() const override final; virtual SizeT vval() const override final;
virtual const VPosBase* vget() const override final;
virtual const VPosBase* vnext() const override final; virtual const VPosBase* vnext() const override final;
virtual Uptr<VPosBase> vplus(const VPosBase* a) const override final; virtual Uptr<VPosBase> vplus(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vtimes(const VPosBase* a) const override final; virtual Uptr<VPosBase> vtimes(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vexec(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vextend(const DPos& a) const override final; virtual Uptr<VPosBase> vextend(const DPos& a) const override final;
virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final; virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final;
virtual Uptr<VPosBase> vextend(const UPos& a) const override final; virtual Uptr<VPosBase> vextend(const UPos& a) const override final;
@ -102,21 +103,19 @@ namespace CNORXZ
{ {
private: private:
const MPos<PosT1,PosT2>* mC = nullptr; const MPos<PosT1,PosT2>* mC = nullptr;
VPosRef<PosT1> mFRef;
VPosRef<PosT2> mNRef; VPosRef<PosT2> mNRef;
public:
typedef MPos<PosT1,PosT2> MPosT;
public:
DEFAULT_MEMBERS(VPosRef); DEFAULT_MEMBERS(VPosRef);
VPosRef(const CPosInterface<MPos<PosT1,PosT2>>* c); VPosRef(const MPos<PosT1,PosT2>* c);
virtual Uptr<VPosBase> copy() const override final; virtual Uptr<VPosBase> copy() const override final;
virtual SizeT vsize() const override final; virtual SizeT vsize() const override final;
virtual SizeT vval() const override final; virtual SizeT vval() const override final;
virtual const VPosBase* vget() const override final;
virtual const VPosBase* vnext() const override final; virtual const VPosBase* vnext() const override final;
virtual Uptr<VPosBase> vplus(const VPosBase* a) const override final; virtual Uptr<VPosBase> vplus(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vtimes(const VPosBase* a) const override final; virtual Uptr<VPosBase> vtimes(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vexec(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vextend(const DPos& a) const override final; virtual Uptr<VPosBase> vextend(const DPos& a) const override final;
virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final; virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final;
virtual Uptr<VPosBase> vextend(const UPos& a) const override final; virtual Uptr<VPosBase> vextend(const UPos& a) const override final;