12#ifndef __cxz_urange_cc_h__
13#define __cxz_urange_cc_h__
31 template <
typename MetaT>
35 mMetaPtr(&mRangePtr->get(0))
38 template <
typename MetaT>
45 template <
typename MetaT>
52 template <
typename MetaT>
59 template <
typename MetaT>
62 return UIndex(mRangePtr, IB::mPos +
n);
65 template <
typename MetaT>
68 return UIndex(mRangePtr, IB::mPos -
n);
71 template <
typename MetaT>
74 return lex() -
i.
lex();
77 template <
typename MetaT>
84 template <
typename MetaT>
91 template <
typename MetaT>
97 template <
typename MetaT>
100 return UPos(mRangePtr->size());
103 template <
typename MetaT>
106 return UPos(mRangePtr->size());
109 template <
typename MetaT>
115 template <
typename MetaT>
118 return mMetaPtr[IB::mPos];
121 template <
typename MetaT>
127 template <
typename MetaT>
130 return mMetaPtr[IB::mPos];
133 template <
typename MetaT>
136 (*this) = mRangePtr->getMeta(
metaPos);
140 template <
typename MetaT>
146 template <
typename MetaT>
150 <<
") smaller than begin index position (" << lex() <<
")");
153 for(
auto i = *
this;
i !=
last+1; ++
i){
159 template <
typename MetaT>
165 template <
typename MetaT>
171 template <
typename MetaT>
174 CXZ_ASSERT(
f[0]*
s[0] == lmax().val(),
"got wrong extension: " <<
f[0]*
s[0]
175 <<
" vs " << lmax().val());
181 template <
typename MetaT>
187 template <
typename MetaT>
193 template <
typename MetaT>
197 if constexpr(I != 0){
201 return UPos(
id == this->
id() ? 1 : 0);
205 template <
typename MetaT>
206 template <
class Xpr,
class F>
209 return For<0,Xpr,F>(this->pmax().val(), this->
id(), xpr, std::forward<F>(
f));
212 template <
typename MetaT>
218 template <
typename MetaT,
class I1>
228 template <
typename MetaT>
232 template <
typename MetaT>
236 template <
typename MetaT>
238 mSpace(space), mRef(
ref) {}
240 template <
typename MetaT>
242 mSpace(space), mRef(
ref) {}
244 template <
typename MetaT>
248 if(mRef !=
nullptr) {
249 mProd = this->fromCreated(
info, {mRef->id()});
251 if(mProd ==
nullptr){
252 RangePtr key = mProd = std::shared_ptr<URange<MetaT>>
254 if(mRef !=
nullptr) { key = mRef; }
255 this->addToCreated(
info, { key->id() }, mProd);
263 template <
typename MetaT>
265 RangeInterface<URange<
MetaT>>(),
268 std::sort(mSpace.begin(), mSpace.end(), std::less<MetaT>());
269 auto itdupl = std::adjacent_find(mSpace.begin(), mSpace.end());
273 template <
typename MetaT>
275 RangeInterface<URange<
MetaT>>(),
278 std::sort(mSpace.begin(), mSpace.end(), std::less<MetaT>());
279 auto itdupl = std::adjacent_find(mSpace.begin(), mSpace.end());
284 template <
typename MetaT>
290 template <
typename MetaT>
293 return mSpace.data();
296 template <
typename MetaT>
299 auto b = mSpace.begin();
300 auto e = mSpace.end();
301 auto i = std::lower_bound(
b,
e, meta, std::less<MetaT>());
307 template <
typename MetaT>
310 return mSpace.size();
313 template <
typename MetaT>
319 template <
typename MetaT>
325 template <
typename MetaT>
331 template <
typename MetaT>
334 return typeid(
MetaT);
337 template <
typename MetaT>
342 space.insert(space.end(),
rx->mSpace.begin(),
rx->mSpace.end());
346 template <
typename MetaT>
356 template <
typename MetaT>
359 template <
typename T>
363 auto rr = std::dynamic_pointer_cast<URange<T>>(r);
365 std::transform(
rr->begin(),
rr->end(),
v.begin(),
366 [](
const T& x) { return static_cast<MetaT>(x); } );
367 return std::dynamic_pointer_cast<URange<MetaT>>
377 static_assert(std::is_fundamental<MetaT>::value,
"got non-fundamental type");
378 CXZ_ASSERT(r->dim() == 1,
"range cast into URange<Int>: source range must have dim = 1, got " << r->dim());
385 CXZ_ERROR(
"no range cast available for input range '" << r->type().name() <<
"'");
390 template <
typename T>
struct is_vector : std::false_type {};
391 template <
typename T,
typename A>
struct is_vector<std::
vector<T,A>> : std::true_type {};
393 template <
typename U>
396 template <
typename T>
400 auto rr = std::dynamic_pointer_cast<URange<T>>(r);
402 std::transform(
rr->begin(),
rr->end(),
v.begin(),
403 [](
const T& x) { return Vector<U> { static_cast<U>(x) }; } );
404 return std::dynamic_pointer_cast<URange<Vector<U>>>
412 template <
typename T, SizeT N>
416 auto rr = std::dynamic_pointer_cast<URange<Arr<T,N>>>(r);
418 std::transform(
rr->begin(),
rr->end(),
v.begin(),
420 return iter<0,N>( [&](auto i) { return static_cast<U>(x[i]); },
421 [](
const auto&...
e) { return Vector<U>{ e... }; });
423 return std::dynamic_pointer_cast<URange<Vector<U>>>
434 if constexpr(std::is_fundamental<U>::value){
435 o = transform<SizeT>(r);
if(o)
return o;
436 o = transform<Int>(r);
if(o)
return o;
437 o = transform<LInt>(r);
if(o)
return o;
438 o = transform<Double>(r);
if(o)
return o;
439 o = atransform<SizeT,2>(r);
if(o)
return o;
440 o = atransform<Int,2>(r);
if(o)
return o;
441 o = atransform<LInt,2>(r);
if(o)
return o;
442 o = atransform<Double,2>(r);
if(o)
return o;
443 o = atransform<SizeT,3>(r);
if(o)
return o;
444 o = atransform<Int,3>(r);
if(o)
return o;
445 o = atransform<LInt,3>(r);
if(o)
return o;
446 o = atransform<Double,3>(r);
if(o)
return o;
449 CXZ_ERROR(
"no range cast available for input range '" << r->type().name() <<
"'");
454 template <
typename MetaT>
455 Sptr<URange<MetaT>> RangeCast<URange<MetaT>>::func(
const RangePtr& r)
457 if constexpr(std::is_fundamental<MetaT>::value or is_vector<MetaT>::value){
458 return URangeCast<MetaT>::cast(r);
461 CXZ_ERROR(
"no range cast available for input range '" << r->type().name() <<
"'");
466 template <
typename MetaT>
#define CXZ_ERROR(errmsg)
#define CXZ_ASSERT(statement, errmsg)
RangePtr prange(const UIndex< MetaType > &last) const
UIndex & reformat(const Vector< SizeT > &f, const Vector< SizeT > &s)
UIndex & operator=(SizeT lexpos)
UIndex operator+(Int n) const
UIndex & at(const MetaT &metaPos)
UIndex & operator+=(Int n)
bool formatIsTrivial() const
Sptr< RangeType > range() const
String stringMeta() const
const MetaT & operator*() const
UIndex operator-(Int n) const
UIndex & operator-=(Int n)
UIndex(const RangePtr &range, SizeT pos=0)
const MetaT & meta() const
const MetaType * get() const
virtual SizeT dim() const override final
virtual const TypeInfo & type() const override final
virtual String stringMeta(SizeT pos) const override final
virtual RangePtr extend(const RangePtr &r) const override final
SizeT getMeta(const MetaType &metaPos) const
virtual const TypeInfo & metaType() const override final
virtual SizeT size() const override final
For expressions declarations.
RangePtr urange(const Vector< MetaT > &space)
constexpr decltype(auto) coproot(const CArrayBase< T > &a, const Sptr< IndexT > &ind)
Sptr< RangeBase > RangePtr
std::vector< T, Allocator< T > > Vector
decltype(auto) xpr(const Sptr< I > &i)
Sptr< Range > rangeCast(const RangePtr r)
decltype(auto) iptrMul(const Sptr< I1 > &a, const Sptr< I2 > &b)
bool formatIsTrivial(const Vector< SizeT > &f, const Vector< SizeT > &s)
String toString(const T &a)
RangePtr prange(const Sptr< RangeT > &range, const Vector< SizeT > &parts)
std::shared_ptr< T > Sptr
Operation types template implementations.
Operation types declarations.
PRange, PRangeFactory and PIndex declaration.
static Sptr< URange< Vector< U > > > transform(const RangePtr &r)
static Sptr< URange< Vector< U > > > atransform(const RangePtr &r)
static Sptr< URange< Vector< U > > > cast(const RangePtr &r)
static Sptr< URange< MetaT > > transform(const RangePtr &r)
static Sptr< URange< MetaT > > cast(const RangePtr &r)
URange, URangeFactory and UIndex declaration.