From 9d85f8df46ac471339d00120475cffc4b9abbd57 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Sun, 11 Apr 2021 16:54:46 +0200 Subject: [PATCH] remove Application classes --- src/include/functional_multi_array.cc.h | 34 ++++++++------------- src/include/pack_num.h | 39 ++++++++----------------- 2 files changed, 24 insertions(+), 49 deletions(-) diff --git a/src/include/functional_multi_array.cc.h b/src/include/functional_multi_array.cc.h index 1cced61..279cd5c 100644 --- a/src/include/functional_multi_array.cc.h +++ b/src/include/functional_multi_array.cc.h @@ -9,26 +9,6 @@ namespace MultiArrayTools * FunctionalMultiArray * ****************************/ - template - struct Application - { - template - static inline T apply(const std::shared_ptr& f, const Meta& m) - { - return (*f)(m); - } - }; - - template <> - struct Application - { - template - static inline T apply(const std::shared_ptr& f, const Meta& m) - { - return Function::apply(m); - } - }; - template FunctionalMultiArray::FunctionalMultiArray(const std::shared_ptr&... ranges, const std::shared_ptr& func) : @@ -51,14 +31,24 @@ namespace MultiArrayTools template const T& FunctionalMultiArray::operator[](const IndexType& i) const { - mVal = Application::template apply(mFunc, i.meta()); + if constexpr(Function::FISSTATIC){ + mVal = Function::apply(i.meta()); + } + else { + mVal = (*mFunc)(i.meta()); + } return mVal; } template const T& FunctionalMultiArray::at(const typename CRange::IndexType::MetaType& meta) const { - mVal = Application::template apply(mFunc,meta); + if constexpr(Function::FISSTATIC){ + mVal = Function::apply(meta); + } + else { + mVal = (*mFunc)(meta); + } return mVal; } diff --git a/src/include/pack_num.h b/src/include/pack_num.h index 4f8c3b1..9a5613a 100644 --- a/src/include/pack_num.h +++ b/src/include/pack_num.h @@ -13,29 +13,6 @@ namespace MultiArrayHelper { - template - struct Application - { - template - static inline auto apply(std::shared_ptr f, Ts... as) - -> decltype((*f)(as...)) - { - return (*f)(as...); - } - }; - - template <> - struct Application - { - template - static inline auto apply(std::shared_ptr f, Ts... as) - -> decltype(OpFunction::apply(as...)) - { - return OpFunction::apply(as...); - } - }; - - template struct PackNum { @@ -174,8 +151,12 @@ namespace MultiArrayHelper typedef typename std::remove_reference(ops))>::type NextOpType; static constexpr size_t NEXT = LAST - NextOpType::SIZE; static_assert(NEXT == 0, "inconsistent array positions"); - typedef decltype(std::get<0>(ops).get(getX<0>( pos ))) ArgT; - return Application::template apply(f, std::get<0>(ops).get(getX<0>( pos )), args...); + if constexpr(OpFunction::FISSTATIC){ + return OpFunction::apply(std::get<0>(ops).get(getX<0>( pos )), args...); + } + else { + return (*f)(std::get<0>(ops).get(getX<0>( pos )), args...); + } } template @@ -184,8 +165,12 @@ namespace MultiArrayHelper typedef typename std::remove_reference(ops))>::type NextOpType; static constexpr size_t NEXT = LAST - NextOpType::SIZE; static_assert(NEXT == 0, "inconsistent array positions"); - typedef decltype(std::get<0>(ops).template vget(getX<0>( pos ))) ArgT; - return Application::template apply(f, std::get<0>(ops).template vget(getX<0>( pos )), args...); + if constexpr(OpFunction::FISSTATIC){ + return OpFunction::apply(std::get<0>(ops).template vget(getX<0>( pos )), args...); + } + else { + return (*f)(std::get<0>(ops).template vget(getX<0>( pos )), args...); + } } template