From e9fde3d90093df8b0e89cc48e8374984be34659b Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Mon, 29 May 2023 23:05:47 +0200 Subject: [PATCH] srange casts + add first eindex implementation --- src/include/ranges/eindex.cc.h | 28 ++++++++++++++++++++++++++++ src/include/ranges/eindex.h | 29 +++++++++++++++++++++++++++++ src/include/ranges/srange.cc.h | 22 ++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 src/include/ranges/eindex.cc.h create mode 100644 src/include/ranges/eindex.h diff --git a/src/include/ranges/eindex.cc.h b/src/include/ranges/eindex.cc.h new file mode 100644 index 0000000..a566125 --- /dev/null +++ b/src/include/ranges/eindex.cc.h @@ -0,0 +1,28 @@ + +#ifndef __cxz_eindex_cc_h__ +#define __cxz_eindex_cc_h__ + +#include "eindex.h" + +namespace CNORXZ +{ + + template + EIndex::EIndex(const SIndex& i) : + SIndex(i) {} + + template + EIndex::EIndex(SIndex&& i) : + SIndex(i) {} + + template + template + decltype(auto) EIndex::ifor(const Xpr& xpr, F&& f) const + { + // TODO: EFor Function argument; meanwhile ignore unused function error!!! + return EFor(this->id(), xpr); + } + +} + +#endif diff --git a/src/include/ranges/eindex.h b/src/include/ranges/eindex.h new file mode 100644 index 0000000..75b498c --- /dev/null +++ b/src/include/ranges/eindex.h @@ -0,0 +1,29 @@ + +#ifndef __cxz_eindex_h__ +#define __cxz_eindex_h__ + +#include "base/base.h" +#include "ranges/index_base.h" +#include "ranges/range_base.h" +#include "xpr/xpr.h" + +namespace CNORXZ +{ + template + class EIndex : public SIndex + { + public: + typedef typename SIndex::IB IB; + typedef typename SIndex::RangeType RangeType; + + DEFAULT_MEMBERS(EIndex); + EIndex(const SIndex& i); + EIndex(SIndex&& i); + + template + decltype(auto) ifor(const Xpr& xpr, F&& f) const; + }; + +} + +#endif diff --git a/src/include/ranges/srange.cc.h b/src/include/ranges/srange.cc.h index e753435..7efd4f9 100644 --- a/src/include/ranges/srange.cc.h +++ b/src/include/ranges/srange.cc.h @@ -289,6 +289,28 @@ namespace CNORXZ return Vector { this->id() }; } + /******************* + * Range Casts * + *******************/ + + template + Sptr> RangeCast>::func(const RangePtr& r) + { + Sptr> tmp; + if(r->type() != typeid(URange)){ + tmp = castRange>(r); + } + else { + tmp = r; + } + CXZ_ASSERT(tmp->size() == S, "cannot cast range of size " << tmp->size() + << " into static range of size " << S); + Arr space; + std::copy(tmp->begin(), tmp->end(), space.begin()); + return std::dynamic_pointer_cast> + ( SRangeFactory(std::move(space)).create() ); + } + } #endif