fix non-static functor issues
This commit is contained in:
parent
6896cc3ca7
commit
405df0c426
3 changed files with 48 additions and 21 deletions
|
@ -108,17 +108,17 @@ namespace MultiArrayTools
|
|||
|
||||
private:
|
||||
mutable T mVal;
|
||||
Function mFunc;
|
||||
std::shared_ptr<Function> mFunc;
|
||||
|
||||
mutable std::shared_ptr<MAType> mMaPtr;
|
||||
|
||||
public:
|
||||
|
||||
DEFAULT_MEMBERS(FunctionalMultiArray);
|
||||
FunctionalMultiArray(const std::shared_ptr<SRanges>&... ranges, const Function& func);
|
||||
FunctionalMultiArray(const std::shared_ptr<SRanges>&... ranges, const std::shared_ptr<Function>& func);
|
||||
FunctionalMultiArray(const std::shared_ptr<SRanges>&... ranges);
|
||||
FunctionalMultiArray(const typename CRange::Space& space);
|
||||
FunctionalMultiArray(const typename CRange::Space& space, const Function& func);
|
||||
FunctionalMultiArray(const typename CRange::Space& space, const std::shared_ptr<Function>& func);
|
||||
|
||||
virtual const T& operator[](const IndexType& i) const override;
|
||||
virtual const T& at(const typename CRange::IndexType::MetaType& meta) const override;
|
||||
|
@ -164,9 +164,9 @@ namespace MultiArrayTools
|
|||
struct Application
|
||||
{
|
||||
template <typename T, class Function, typename Meta>
|
||||
static inline T apply(const Function& f, const Meta& m)
|
||||
static inline T apply(const std::shared_ptr<Function>& f, const Meta& m)
|
||||
{
|
||||
return f(m);
|
||||
return (*f)(m);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -174,7 +174,7 @@ namespace MultiArrayTools
|
|||
struct Application<true>
|
||||
{
|
||||
template <typename T, class Function, typename Meta>
|
||||
static inline T apply(const Function& f, const Meta& m)
|
||||
static inline T apply(const std::shared_ptr<Function>& f, const Meta& m)
|
||||
{
|
||||
return Function::apply(m);
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ namespace MultiArrayTools
|
|||
|
||||
template <typename T, class Function, class... SRanges>
|
||||
FunctionalMultiArray<T,Function,SRanges...>::FunctionalMultiArray(const std::shared_ptr<SRanges>&... ranges,
|
||||
const Function& func) :
|
||||
const std::shared_ptr<Function>& func) :
|
||||
MultiArrayBase<T,SRanges...>(ranges...), mFunc(func) {}
|
||||
|
||||
template <typename T, class Function, class... SRanges>
|
||||
|
@ -195,7 +195,7 @@ namespace MultiArrayTools
|
|||
|
||||
template <typename T, class Function, class... SRanges>
|
||||
FunctionalMultiArray<T,Function,SRanges...>::FunctionalMultiArray(const typename CRange::Space& space,
|
||||
const Function& func) :
|
||||
const std::shared_ptr<Function>& func) :
|
||||
MultiArrayBase<T,SRanges...>(space), mFunc(func) {}
|
||||
|
||||
|
||||
|
|
|
@ -373,11 +373,37 @@ namespace MultiArrayTools
|
|||
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
template <bool FISSTATIC>
|
||||
struct OpMaker
|
||||
{
|
||||
template <class OpFunction, class... Ops>
|
||||
static inline auto mkOperation(const std::shared_ptr<OpFunction>& f, const Ops&... ops)
|
||||
-> Operation<typename OpFunction::value_type,OpFunction,Ops...>
|
||||
{
|
||||
return Operation<typename OpFunction::value_type,OpFunction,Ops...>(f,ops...);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct OpMaker<true>
|
||||
{
|
||||
template <class OpFunction, class... Ops>
|
||||
static inline auto mkOperation(const std::shared_ptr<OpFunction>& f, const Ops&... ops)
|
||||
-> Operation<typename OpFunction::value_type,OpFunction,Ops...>
|
||||
{
|
||||
return Operation<typename OpFunction::value_type,OpFunction,Ops...>(ops...);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
template <class OpFunction, class... Ops>
|
||||
auto mkOperation(const OpFunction& f, const Ops&... ops)
|
||||
auto mkOperation(const std::shared_ptr<OpFunction>& f, const Ops&... ops)
|
||||
-> Operation<typename OpFunction::value_type,OpFunction,Ops...>
|
||||
{
|
||||
return Operation<typename OpFunction::value_type,OpFunction,Ops...>(ops...);
|
||||
return OpMaker<OpFunction::FISSTATIC>::mkOperation(f, ops...);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -35,8 +35,7 @@ namespace MultiArrayTools
|
|||
typedef ValueRange<U> RangeType;
|
||||
typedef ValueIndex IType;
|
||||
|
||||
ValueIndex(const U& val); // default range
|
||||
ValueIndex(U&& val); // default range
|
||||
ValueIndex(const std::shared_ptr<RangeType>& rptr);
|
||||
|
||||
static constexpr IndexType sType() { return IndexType::SINGLE; }
|
||||
static constexpr size_t totalDim() { return 1; }
|
||||
|
@ -124,6 +123,12 @@ namespace MultiArrayTools
|
|||
static constexpr size_t SIZE = 1;
|
||||
static constexpr bool HASMETACONT = false;
|
||||
|
||||
static std::shared_ptr<ValueRange> Default()
|
||||
{
|
||||
ValueRangeFactory<U> vrf;
|
||||
return std::dynamic_pointer_cast<ValueRange>( vrf.create() );
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
ValueRange() = default;
|
||||
|
@ -147,19 +152,15 @@ namespace MultiArrayTools
|
|||
std::shared_ptr<RangeBase> mkDefaultValueRange()
|
||||
{
|
||||
ValueRangeFactory<U> vrf;
|
||||
return vrf->create();
|
||||
return vrf.create();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
ValueIndex<U>::ValueIndex(const U& val) : IndexInterface<ValueIndex<U>,U>(mkDefaultValueRange<U>(), 0),
|
||||
mExplicitRangePtr(std::dynamic_pointer_cast<RangeType>(IB::mRangePtr)),
|
||||
mMeta(val) {}
|
||||
|
||||
template <typename U>
|
||||
ValueIndex<U>::ValueIndex(U&& val) : IndexInterface<ValueIndex<U>,U>(mkDefaultValueRange<U>(), 0),
|
||||
mExplicitRangePtr(std::dynamic_pointer_cast<RangeType>(IB::mRangePtr)),
|
||||
mMeta(val) {}
|
||||
ValueIndex<U>::ValueIndex(const std::shared_ptr<RangeType>& rptr) :
|
||||
IndexInterface<ValueIndex<U>,U>(rptr, 0),
|
||||
mExplicitRangePtr(std::dynamic_pointer_cast<RangeType>(IB::mRangePtr))
|
||||
{}
|
||||
|
||||
template <typename U>
|
||||
IndexType ValueIndex<U>::type() const
|
||||
|
|
Loading…
Reference in a new issue