re-implement DIndex ifor (-> template)
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
0f0a01793c
commit
3b7040447c
6 changed files with 156 additions and 5 deletions
|
@ -170,6 +170,9 @@ namespace CNORXZ
|
|||
template <class Op>
|
||||
constexpr OpCont<T,IndexT>& OpCont<T,IndexT>::operator=(const Op& o)
|
||||
{
|
||||
// TODO: build and execute assign expression forwarding outer index
|
||||
// if a1 and a2 are non-expression types (like it is the case now),
|
||||
// just do what is currently implemented
|
||||
OI::a(mIndex, [](auto& a1, const auto& a2) { a1 = a2; }, o);
|
||||
return *this;
|
||||
}
|
||||
|
@ -375,6 +378,38 @@ namespace CNORXZ
|
|||
return Operation<F,Ops...>(std::forward<F>(f), ops...);
|
||||
}
|
||||
|
||||
template <class Tar, class Src>
|
||||
constexpr decltype(auto) assignxpr(const Tar& tar, const Src& src)
|
||||
{
|
||||
static_assert(is_xpr<Tar>::value, "expected expression");
|
||||
if constexpr(is_xpr<Src>::value){
|
||||
return operation([](auto& a, const auto& b) { a = b; }, tar, src);
|
||||
}
|
||||
else {
|
||||
return operation([&](auto& a) { a = src; }, tar);
|
||||
}
|
||||
}
|
||||
|
||||
template <class Tar, class Src>
|
||||
constexpr decltype(auto) assignxpr(Tar& tar, const Src& src)
|
||||
{
|
||||
if constexpr(is_xpr<Tar>::value){
|
||||
if constexpr(is_xpr<Src>::value){
|
||||
return operation([](auto& a, const auto& b) { a = b; }, tar, src);
|
||||
}
|
||||
else {
|
||||
return operation([&](auto& a) { a = src; }, tar);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if constexpr(is_xpr<Src>::value){
|
||||
return operation([&](const auto& b) { tar = b; }, src);
|
||||
}
|
||||
else {
|
||||
return operation([&]() { tar = src; });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*********************
|
||||
* Contraction *
|
||||
|
|
|
@ -212,6 +212,12 @@ namespace CNORXZ
|
|||
template <class F, class... Ops>
|
||||
constexpr decltype(auto) operation(F&& f, const Ops&... ops);
|
||||
|
||||
template <class Tar, class Src>
|
||||
constexpr decltype(auto) assignxpr(const Tar& tar, const Src& src);
|
||||
|
||||
template <class Tar, class Src>
|
||||
constexpr decltype(auto) assignxpr(Tar& tar, const Src& src);
|
||||
|
||||
template <class F, class... Ops>
|
||||
struct op_size<Operation<F,Ops...>>
|
||||
{ static constexpr SizeT value = ( op_size<Ops>::value + ... ); };
|
||||
|
|
|
@ -32,13 +32,11 @@ namespace CNORXZ
|
|||
return mI->ifor( DXpr<None>(xpr), std::forward<F>(f) );
|
||||
}
|
||||
else {
|
||||
CXZ_ERROR("IMPLEMENT!!!");
|
||||
return DXpr<R>();
|
||||
return DXpr<R>( bufxpr([&](auto x){ return mI->ifor( DXpr<None>( assignxpr(x, xpr) ), NoF {} ); }) );
|
||||
}
|
||||
}
|
||||
else {
|
||||
CXZ_ERROR("IMPLEMENT!!!");
|
||||
return DXpr<R>();
|
||||
return DXpr<R>( bufxpr([&](auto x){ return mI->ifor( DXpr<None>( assignxpr(x, xpr) ), NoF {} ); }) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
71
src/include/xpr/buf_xpr.cc.h
Normal file
71
src/include/xpr/buf_xpr.cc.h
Normal file
|
@ -0,0 +1,71 @@
|
|||
|
||||
#include "buf_xpr.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
template <typename T, class IXprF>
|
||||
BufXpr<T,IXprF>::BufXpr(const BufXpr& in) :
|
||||
mBuf(in.mBuf),
|
||||
mIXprF(in.mIXprF),
|
||||
mIXpr(mIXprF(mBuf))
|
||||
{}
|
||||
|
||||
template <typename T, class IXprF>
|
||||
BufXpr<T,IXprF>::BufXpr(BufXpr&& in) :
|
||||
mBuf(std::move(in.mBuf)),
|
||||
mIXprF(std::move(in.mIXprF)),
|
||||
mIXpr(mIXprF(mBuf))
|
||||
{}
|
||||
|
||||
template <typename T, class IXprF>
|
||||
BufXpr& BufXpr<T,IXprF>::operator=(const BufXpr& in)
|
||||
{
|
||||
mBuf = in.mBuf;
|
||||
mIXprF = in.mIXprF;
|
||||
mIXpr = mIXprF(mBuf);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, class IXprF>
|
||||
BufXpr& BufXpr<T,IXprF>::operator=(BufXpr&& in)
|
||||
{
|
||||
mBuf = std::move(in.mBuf);
|
||||
mIXprF = std::move(in.mIXprF);
|
||||
mIXpr = mIXprF(mBuf);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, class IXprF>
|
||||
constexpr BufXpr<T,IXprF>::BufXpr(IXprF&& ixprf) :
|
||||
mIXprF(std::forward<IXprF>(ixprf)),
|
||||
mIXpr(mIXprF(mBuf))
|
||||
{}
|
||||
|
||||
template <typename T, class IXprF>
|
||||
template <class PosT>
|
||||
inline decltype(auto) BufXpr<T,IXprF>::operator()(const PosT& last) const
|
||||
{
|
||||
mIXpr(last);
|
||||
return mBuf;
|
||||
}
|
||||
|
||||
template <typename T, class IXprF>
|
||||
inline decltype(auto) BufXpr<T,IXprF>::operator()() const
|
||||
{
|
||||
mIXpr();
|
||||
return mBuf;
|
||||
}
|
||||
|
||||
template <typename T, class IXprF>
|
||||
template <SizeT I>
|
||||
inline decltype(auto) BufXpr<T,IXprF>::rootSteps(const IndexId<I>& id) const
|
||||
{
|
||||
return mIXpr.rootSteps(id);
|
||||
}
|
||||
|
||||
template <typename T, class IXprF>
|
||||
constexpr decltype(auto) bufxpr(IXprF&& ixprf)
|
||||
{
|
||||
return BufXpr<T,IXprF>( std::forward<IXprF>(ixprf) );
|
||||
}
|
||||
}
|
35
src/include/xpr/buf_xpr.h
Normal file
35
src/include/xpr/buf_xpr.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
|
||||
#include "xpr_base.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
template <typename T, class IXprF>
|
||||
class BufXpr : public XprInterface<BufXpr>
|
||||
{
|
||||
public:
|
||||
BufXpr() = default;
|
||||
BufXpr(const BufXpr& in);
|
||||
BufXpr(BufXpr&& in);
|
||||
BufXpr& operator=(const BufXpr& in);
|
||||
BufXpr& operator=(BufXpr&& in);
|
||||
|
||||
constexpr BufXpr(IXprF&& ixprf);
|
||||
|
||||
template <class PosT>
|
||||
inline decltype(auto) operator()(const PosT& last) const;
|
||||
|
||||
inline decltype(auto) operator()() const;
|
||||
|
||||
template <SizeT I>
|
||||
inline decltype(auto) rootSteps(const IndexId<I>& id) const;
|
||||
|
||||
private:
|
||||
T mBuf;
|
||||
IXprF mIXprF; // function to create set-buffer-xpr (reference to mBuf as arg)
|
||||
typedef decltype(mIXprF(mBuf)) IXpr;
|
||||
IXpr mIXpr;
|
||||
};
|
||||
|
||||
template <typename T, class IXprF>
|
||||
constexpr decltype(auto) bufxpr(IXprF&& ixprf);
|
||||
}
|
|
@ -75,6 +75,12 @@ namespace CNORXZ
|
|||
template <SizeT I>
|
||||
inline DPos rootSteps(const IndexId<I>& id) const;
|
||||
};
|
||||
|
||||
template <class X>
|
||||
struct is_xpr
|
||||
{
|
||||
static constexpr bool value = std::is_base_of<XprInterface<X>,X>::value;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue