DXpr: consistent handling of pos types

This commit is contained in:
Christian Zimmermann 2024-11-14 00:29:37 -08:00
parent 8d7511b6c6
commit 1743fd196a
4 changed files with 91 additions and 2 deletions

View file

@ -17,6 +17,7 @@
#include "wrange.cc.h" #include "wrange.cc.h"
#include "srange.cc.h" #include "srange.cc.h"
#include "crange.cc.h" #include "crange.cc.h"
#include "yrange.cc.h"
#include "prange.cc.h" #include "prange.cc.h"
#include "dindex.cc.h" #include "dindex.cc.h"
#include "lindex.cc.h" #include "lindex.cc.h"

View file

@ -0,0 +1,34 @@
// -*- C++ -*-
/**
@file include/ranges/yrange.cc.h
@brief YRange and YIndex template implementations.
Copyright (c) 2024 Christian Zimmermann. All rights reserved.
Mail: chizeta@f3l.de
**/
#ifndef __cxz_yrange_cc_h__
#define __cxz_yrange_cc_h__
#include "yrange.h"
#include "index_mul.h"
namespace CNORXZ
{
template <class Xpr>
DXpr<None> YIndex::ifor(const Xpr& xpr, NoF&& f) const
{
return this->ifor( DXpr<None>(xpr), std::forward<NoF>(f) );
}
template <class I>
decltype(auto) operator*(const Sptr<YIndex>& a, const Sptr<I>& b)
{
return iptrMul(a, b);
}
}
#endif

View file

@ -154,6 +154,10 @@ namespace CNORXZ
/** @copydoc IndexInterface::ifor() */ /** @copydoc IndexInterface::ifor() */
DXpr<None> ifor(const DXpr<None>& xpr, NoF&& f) const; DXpr<None> ifor(const DXpr<None>& xpr, NoF&& f) const;
/** @copydoc IndexInterface::ifor() */
template <class Xpr>
DXpr<None> ifor(const Xpr& xpr, NoF&& f) const;
/** @copydoc IndexInterface::formatIsTrivial() */ /** @copydoc IndexInterface::formatIsTrivial() */
bool formatIsTrivial() const; bool formatIsTrivial() const;
@ -361,6 +365,12 @@ namespace CNORXZ
static Sptr<YRange> func(const RangePtr& r); static Sptr<YRange> func(const RangePtr& r);
}; };
/** Make index pack of a YIndex and another index.
@param a pointer to YIndex.
@param b pointer to another index.
*/
template <class I>
decltype(auto) operator*(const Sptr<YIndex>& a, const Sptr<I>& b);
} }

View file

@ -16,6 +16,35 @@
namespace CNORXZ namespace CNORXZ
{ {
// TODO: move to a better place!!!
template <class PosT>
struct PosFromDPos
{
static constexpr decltype(auto) mk(const DPos& pos)
{
if constexpr(std::is_same<PosT,DPos>::value or std::is_same<PosT,DPosRef>::value){
return pos;
}
else {
return UPos(pos.val());
}
}
};
template <class BPosT, class NPosT>
struct PosFromDPos<MPos<BPosT,NPosT>>
{
static constexpr decltype(auto) mk(const DPos& pos)
{
return mkMPos( PosFromDPos<BPosT>::mk(pos), PosFromDPos<NPosT>::mk( pos.sub() ) );
}
};
template <class PosT>
constexpr decltype(auto) mkMPosFromDPos(const DPos& pos)
{
return PosFromDPos<PosT>::mk(pos);
}
/*==========+ /*==========+
| VXpr | | VXpr |
@ -35,13 +64,28 @@ namespace CNORXZ
template <typename T, class Xpr> template <typename T, class Xpr>
T VXpr<T,Xpr>::vexec(const DPos& last) const T VXpr<T,Xpr>::vexec(const DPos& last) const
{ {
return (*this)(last); typedef typename std::remove_reference<decltype(this->rootSteps(IndexId<0>{}))>::type Ext;
typedef decltype((*this)()) RetT;
if constexpr(std::is_same<RetT,void>::value){
(*this)(mkMPosFromDPos<Ext>(last));
return None {};
}
else {
return (*this)(mkMPosFromDPos<Ext>(last));
}
} }
template <typename T, class Xpr> template <typename T, class Xpr>
T VXpr<T,Xpr>::vexec() const T VXpr<T,Xpr>::vexec() const
{ {
return (*this)(); typedef decltype((*this)()) RetT;
if constexpr(std::is_same<RetT,void>::value){
(*this)();
return None {};
}
else {
return (*this)();
}
} }
template <typename T, class Xpr> template <typename T, class Xpr>