#include "functional_array.h" namespace CNORXZ { /**************************** * FunctionalArray * ****************************/ template FunctionalArray::FunctionalArray(const std::shared_ptr&... ranges, const std::shared_ptr& func) : ArrayBase(ranges...), mFunc(func) {} template FunctionalArray::FunctionalArray(const std::shared_ptr&... ranges) : ArrayBase(ranges...) {} template FunctionalArray::FunctionalArray(const typename CRange::Space& space) : ArrayBase(space) {} template FunctionalArray::FunctionalArray(const typename CRange::Space& space, const std::shared_ptr& func) : ArrayBase(space), mFunc(func) {} template const T& FunctionalArray::operator[](const IndexType& i) const { if constexpr(Function::FISSTATIC){ mVal = Function::apply(i.meta()); } else { mVal = (*mFunc)(i.meta()); } return mVal; } template const T& FunctionalArray::at(const typename CRange::IndexType::MetaType& meta) const { if constexpr(Function::FISSTATIC){ mVal = Function::apply(meta); } else { mVal = (*mFunc)(meta); } return mVal; } template const T* FunctionalArray::data() const { return &mVal; } template bool FunctionalArray::isConst() const { return true; } template bool FunctionalArray::isSlice() const { return false; } template std::shared_ptr > FunctionalArray::anonymous(bool slice) const { assert(0); // think about it carefully return nullptr; } template ConstOperationRoot FunctionalArray:: operator()(const std::shared_ptr&... inds) const { if(not mMaPtr){ mMaPtr = std::make_shared( MAB::mRange->space() ); (*mMaPtr)(inds...) = exec(inds...); } return ConstOperationRoot( *mMaPtr, inds... ); } template auto FunctionalArray:: exec(const std::shared_ptr&... inds) const -> Operation...> { return mkOperation( mFunc, MetaOperationRoot( inds ) ... ); } } // namespace CNORXZ