operation via lambda expression ( a(T,args...) function in OperationClass)
This commit is contained in:
parent
29c0f48f77
commit
1aa5ed10d9
3 changed files with 58 additions and 2 deletions
|
@ -2,6 +2,8 @@
|
|||
#ifndef __arith_h__
|
||||
#define __arith_h__
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
|
||||
|
@ -14,6 +16,13 @@ namespace MultiArrayTools
|
|||
{
|
||||
return ArgPack<N-1>::template mk<F,Tuple,decltype(std::get<N>(tp)),As...>(tp, std::get<N>(tp), as...);
|
||||
}
|
||||
|
||||
template <class F, class Tuple, typename... As>
|
||||
static inline auto mkd(const F& ff, const Tuple& tp, As... as)
|
||||
-> decltype(ArgPack<N-1>::template mkd<F,Tuple,decltype(std::get<N>(tp)),As...>(ff, tp, std::get<N>(tp), as...))
|
||||
{
|
||||
return ArgPack<N-1>::template mkd<F,Tuple,decltype(std::get<N>(tp)),As...>(ff, tp, std::get<N>(tp), as...);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
|
@ -25,6 +34,13 @@ namespace MultiArrayTools
|
|||
{
|
||||
return F::apply(std::get<0>(tp), as...);
|
||||
}
|
||||
|
||||
template <class F, class Tuple, typename... As>
|
||||
static inline auto mkd(const F& ff, const Tuple& tp, As... as)
|
||||
-> decltype(ff(std::get<0>(tp), as...))
|
||||
{
|
||||
return ff(std::get<0>(tp), as...);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, class F, typename... As>
|
||||
|
@ -45,7 +61,8 @@ namespace MultiArrayTools
|
|||
return ArgPack<sizeof...(As)-1>::template mk<F,std::tuple<As...> >(arg);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
// OPERATIONS (STATIC)
|
||||
template <typename T>
|
||||
struct identity : public StaticFunctionBase<T, identity<T>, T>
|
||||
|
@ -107,6 +124,32 @@ namespace MultiArrayTools
|
|||
}
|
||||
};
|
||||
|
||||
// OPERATIONS (STATIC)
|
||||
template <typename R, typename... Args>
|
||||
class function
|
||||
{
|
||||
public:
|
||||
static constexpr bool FISSTATIC = false;
|
||||
|
||||
private:
|
||||
std::function<R(Args...)> mF;
|
||||
|
||||
public:
|
||||
|
||||
function() = default;
|
||||
function(const std::function<R(Args...)>& in) : mF(in) {}
|
||||
|
||||
inline R operator()(const Args&... args)
|
||||
{
|
||||
return mF(args...);
|
||||
}
|
||||
|
||||
inline R operator()(const std::tuple<Args...>& args)
|
||||
{
|
||||
return ArgPack<sizeof...(Args)-1>::template mkd<std::function<R(Args...)>,std::tuple<Args...>>>(mF, args);
|
||||
}
|
||||
};
|
||||
|
||||
#include <cmath>
|
||||
#define regFunc1(fff) template <typename T>\
|
||||
struct x_##fff : public StaticFunctionBase<T, x_##fff<T>, T> {\
|
||||
|
|
|
@ -76,6 +76,15 @@ namespace MultiArrayTools
|
|||
(THIS(), inds...);
|
||||
}
|
||||
|
||||
template <typename T, class OperationClass>
|
||||
template <typename R, class... Args>
|
||||
auto OperationBase<T,OperationClass>::a(const function<R,T,typename Args::value_type...>& ll,
|
||||
const Args&... args) const
|
||||
-> Operation<R,function<R,T,typename Args::value_type...>,OperationClass, Args...>
|
||||
{
|
||||
return Operation<R,function<R,T,typename Args::value_type...>,OperationClass, Args...>(THIS(), args...);
|
||||
}
|
||||
|
||||
/*****************************************
|
||||
* OperationMaster::AssignmentExpr *
|
||||
*****************************************/
|
||||
|
|
|
@ -60,7 +60,11 @@ namespace MultiArrayTools
|
|||
template <class... Indices>
|
||||
auto slc(const std::shared_ptr<Indices>&... inds) const
|
||||
-> SliceContraction<T,OperationClass,Indices...>;
|
||||
|
||||
|
||||
template <typename R, class... Args> // Args = Operation Classes
|
||||
auto a(const function<R,T,typename Args::value_type...>& ll, const Args&... args) const
|
||||
-> Operation<R,function<R,T,typename Args::value_type...>,OperationClass, Args...>;
|
||||
|
||||
private:
|
||||
friend OperationClass;
|
||||
friend OperationTemplate<T,OperationClass>;
|
||||
|
|
Loading…
Reference in a new issue