From b257ab4db399337a53c3c9e05509229eda76c358 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Thu, 13 Sep 2018 17:42:16 +0200 Subject: [PATCH] some utilities --- src/include/helper_tools.h | 18 ++++++++++++++ src/include/type_operations.h | 45 +++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/src/include/helper_tools.h b/src/include/helper_tools.h index 7a40a42..4e8c8c1 100644 --- a/src/include/helper_tools.h +++ b/src/include/helper_tools.h @@ -52,6 +52,12 @@ namespace MultiArrayTools template inline void For(const std::shared_ptr& ind, const std::function& ll); + + template + inline auto mkOp(const std::shared_ptr& i) + -> decltype(std::declval,typename Index::RangeType> > + ().exec(i)); } /* ========================= * @@ -151,6 +157,18 @@ namespace MultiArrayTools } } + template + inline auto mkOp(const std::shared_ptr& i) + -> decltype(std::declval,typename Index::RangeType> > + ().exec(i)) + { + FunctionalMultiArray, + typename Index::RangeType> fma(i->range()); + return fma.exec(i); + } + } #endif diff --git a/src/include/type_operations.h b/src/include/type_operations.h index 27a65dd..24e634b 100644 --- a/src/include/type_operations.h +++ b/src/include/type_operations.h @@ -3,6 +3,8 @@ #define __type_operations_h__ #include +#include +#include #include "base_def.h" #include "mbase_def.h" @@ -16,6 +18,8 @@ namespace MultiArrayTools using namespace MultiArrayHelper; } + // MultiArray + template class operate { @@ -54,7 +58,48 @@ namespace MultiArrayTools }; + // vector + template + class getter + { + private: + size_t mPos; + public: + static constexpr bool FISSTATIC = false; + + getter(size_t i) : mPos(i) {} + + inline T operator()(const std::vector& in) + { + return in[mPos]; + } + }; + + template + std::vector& operator+=(std::vector& a, const std::vector& b) + { + std::transform(a.begin(), a.end(), b.begin(), a.begin(), std::plus()); + return a; + } + + template + class OperationTemplate,OperationClass> : public OperationBase,OperationClass> + { + public: + typedef OperationBase,OperationClass> OB; + + auto operator[](size_t i) + -> Operation,OperationClass> + { + std::shared_ptr > ff = std::make_shared >(i); + return Operation,OperationClass>(ff,OB::THIS()); + } + + private: + OperationTemplate() = default; + friend OperationClass; + }; } // namespace MultiArrayTools