some utilities

This commit is contained in:
Christian Zimmermann 2018-09-13 17:42:16 +02:00
parent 9b79c96eea
commit b257ab4db3
2 changed files with 63 additions and 0 deletions

View file

@ -52,6 +52,12 @@ namespace MultiArrayTools
template <class IndexType>
inline void For(const std::shared_ptr<IndexType>& ind, const std::function<void(void)>& ll);
template <class Index>
inline auto mkOp(const std::shared_ptr<Index>& i)
-> decltype(std::declval<FunctionalMultiArray<typename Index::MetaType,
identity<typename Index::MetaType>,typename Index::RangeType> >
().exec(i));
}
/* ========================= *
@ -151,6 +157,18 @@ namespace MultiArrayTools
}
}
template <class Index>
inline auto mkOp(const std::shared_ptr<Index>& i)
-> decltype(std::declval<FunctionalMultiArray<typename Index::MetaType,
identity<typename Index::MetaType>,typename Index::RangeType> >
().exec(i))
{
FunctionalMultiArray<typename Index::MetaType,
identity<typename Index::MetaType>,
typename Index::RangeType> fma(i->range());
return fma.exec(i);
}
}
#endif

View file

@ -3,6 +3,8 @@
#define __type_operations_h__
#include <cstdlib>
#include <vector>
#include <algorithm>
#include "base_def.h"
#include "mbase_def.h"
@ -16,6 +18,8 @@ namespace MultiArrayTools
using namespace MultiArrayHelper;
}
// MultiArray
template <typename T, class... Ranges>
class operate
{
@ -54,7 +58,48 @@ namespace MultiArrayTools
};
// vector
template <typename T>
class getter
{
private:
size_t mPos;
public:
static constexpr bool FISSTATIC = false;
getter(size_t i) : mPos(i) {}
inline T operator()(const std::vector<T>& in)
{
return in[mPos];
}
};
template <typename T>
std::vector<T>& operator+=(std::vector<T>& a, const std::vector<T>& b)
{
std::transform(a.begin(), a.end(), b.begin(), a.begin(), std::plus<T>());
return a;
}
template <class OperationClass, typename T>
class OperationTemplate<std::vector<T>,OperationClass> : public OperationBase<std::vector<T>,OperationClass>
{
public:
typedef OperationBase<std::vector<T>,OperationClass> OB;
auto operator[](size_t i)
-> Operation<T,getter<T>,OperationClass>
{
std::shared_ptr<getter<T> > ff = std::make_shared<getter<T> >(i);
return Operation<T,getter<T>,OperationClass>(ff,OB::THIS());
}
private:
OperationTemplate() = default;
friend OperationClass;
};
} // namespace MultiArrayTools