some utilities + corrections in 'call by lambda' operation
This commit is contained in:
parent
be205808e4
commit
ca2e47b986
8 changed files with 90 additions and 7 deletions
|
@ -99,7 +99,15 @@ namespace MultiArrayTools
|
|||
typename Index::RangeType> fma(i->range());
|
||||
return fma.exec(i);
|
||||
}
|
||||
|
||||
|
||||
template <typename R, typename... Ts>
|
||||
struct Func
|
||||
{
|
||||
static inline std::shared_ptr<function<R,Ts...>> mk(const std::function<R(Ts...)>& ll)
|
||||
{
|
||||
return std::make_shared<function<R,Ts...>>(ll);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -33,6 +33,13 @@ namespace MultiArrayTools
|
|||
return (*this)[ii];
|
||||
}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
const T& MultiArrayBase<T,SRanges...>::operator[](const std::tuple<IPTR<typename SRanges::IndexType>...>& is) const
|
||||
{
|
||||
IndexType ii(*mProtoI);
|
||||
ii(is);
|
||||
return (*this)[ii];
|
||||
}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
size_t MultiArrayBase<T,SRanges...>::size() const
|
||||
|
@ -164,6 +171,14 @@ namespace MultiArrayTools
|
|||
return (*this)[ii];
|
||||
}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
T& MutableMultiArrayBase<T,SRanges...>::operator[](const std::tuple<IPTR<typename SRanges::IndexType>...>& is)
|
||||
{
|
||||
IndexType ii(*MAB::mProtoI);
|
||||
ii(is);
|
||||
return (*this)[ii];
|
||||
}
|
||||
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
bool MutableMultiArrayBase<T,SRanges...>::isConst() const
|
||||
|
|
|
@ -16,6 +16,39 @@
|
|||
namespace MultiArrayTools
|
||||
{
|
||||
|
||||
template <class IndexType>
|
||||
using IPTR = std::shared_ptr<IndexType>;
|
||||
|
||||
template <class IndexType1, class IndexType2>
|
||||
inline auto operator|(const IPTR<IndexType1>& i1, const IPTR<IndexType2>& i2)
|
||||
-> decltype(std::make_tuple(i1->THIS(),i2->THIS()))
|
||||
{
|
||||
return std::make_tuple(i1->THIS(),i2->THIS());
|
||||
}
|
||||
|
||||
template <class IndexType1, class... IndexTypes2>
|
||||
inline auto operator|(const IPTR<IndexType1>& i1,
|
||||
const std::tuple<IPTR<IndexTypes2>...>& i2)
|
||||
-> decltype(std::tuple_cat(std::make_tuple(i1),i2))
|
||||
{
|
||||
return std::tuple_cat(std::make_tuple(i1),i2);
|
||||
}
|
||||
|
||||
template <class IndexType2, class... IndexTypes1>
|
||||
inline auto operator|(const std::tuple<IPTR<IndexTypes1>...>& i1,
|
||||
const IPTR<IndexType2>& i2)
|
||||
-> decltype(std::tuple_cat(i1,std::make_tuple(i2)))
|
||||
{
|
||||
return std::tuple_cat(i1,std::make_tuple(i2));
|
||||
}
|
||||
|
||||
template <class IndexType>
|
||||
inline auto operator~(const IPTR<IndexType>& i)
|
||||
-> decltype(std::make_tuple(i))
|
||||
{
|
||||
return std::make_tuple(i);
|
||||
}
|
||||
|
||||
// Explicitely specify subranges in template argument !!!
|
||||
template <typename T, class... SRanges>
|
||||
class MultiArrayBase
|
||||
|
@ -41,7 +74,8 @@ namespace MultiArrayTools
|
|||
|
||||
template <typename X>
|
||||
const T& operator[](const ContainerIndex<X,typename SRanges::IndexType...>& i);
|
||||
|
||||
const T& operator[](const std::tuple<IPTR<typename SRanges::IndexType>...>& is) const;
|
||||
|
||||
virtual const T& operator[](const IndexType& i) const = 0;
|
||||
virtual const T& at(const typename CRange::IndexType::MetaType& meta) const = 0;
|
||||
|
||||
|
@ -101,7 +135,8 @@ namespace MultiArrayTools
|
|||
|
||||
template <typename X>
|
||||
T& operator[](const ContainerIndex<X,typename SRanges::IndexType...>& i);
|
||||
|
||||
T& operator[](const std::tuple<IPTR<typename SRanges::IndexType>...>& is);
|
||||
|
||||
virtual T& operator[](const IndexType& i) = 0;
|
||||
virtual T& at(const typename CRange::IndexType::MetaType& meta) = 0;
|
||||
|
||||
|
|
|
@ -78,11 +78,11 @@ namespace MultiArrayTools
|
|||
|
||||
template <typename T, class OperationClass>
|
||||
template <typename R, class... Args>
|
||||
auto OperationBase<T,OperationClass>::a(const function<R,T,typename Args::value_type...>& ll,
|
||||
auto OperationBase<T,OperationClass>::a(const std::shared_ptr<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...);
|
||||
return Operation<R,function<R,T,typename Args::value_type...>,OperationClass, Args...>(ll, THIS(), args...);
|
||||
}
|
||||
|
||||
/*****************************************
|
||||
|
|
|
@ -62,7 +62,7 @@ namespace MultiArrayTools
|
|||
-> 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
|
||||
auto a(const std::shared_ptr<function<R,T,typename Args::value_type...>>& ll, const Args&... args) const
|
||||
-> Operation<R,function<R,T,typename Args::value_type...>,OperationClass, Args...>;
|
||||
|
||||
private:
|
||||
|
|
|
@ -82,6 +82,7 @@ namespace MultiArrayTools
|
|||
|
||||
ContainerIndex& sync(); // recalculate 'IB::mPos' when externalControl == true
|
||||
ContainerIndex& operator()(const std::shared_ptr<Indices>&... inds); // control via external indices
|
||||
ContainerIndex& operator()(const std::tuple<std::shared_ptr<Indices>...>& inds);
|
||||
ContainerIndex& operator()(); // -> sync; just to shorten the code
|
||||
|
||||
// ==== >>>>> STATIC POLYMORPHISM <<<<< ====
|
||||
|
@ -305,6 +306,14 @@ namespace MultiArrayTools
|
|||
return sync();
|
||||
}
|
||||
|
||||
template <typename T, class... Indices>
|
||||
ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::operator()(const std::tuple<std::shared_ptr<Indices>...>& inds)
|
||||
{
|
||||
RPackNum<sizeof...(Indices)-1>::swapIndices(mIPack, inds);
|
||||
mExternControl = true;
|
||||
return sync();
|
||||
}
|
||||
|
||||
template <typename T, class... Indices>
|
||||
ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::operator()()
|
||||
{
|
||||
|
|
|
@ -214,6 +214,13 @@ namespace MultiArrayHelper
|
|||
RPackNum<N-1>::swapIndices(ipack, ninds...);
|
||||
}
|
||||
|
||||
template <class Pack, class... Indices>
|
||||
static void swapIndices(Pack& ipack, const std::tuple<std::shared_ptr<Indices>...>& ninds)
|
||||
{
|
||||
std::get<N>(ipack) = std::get<N>(ninds);
|
||||
RPackNum<N-1>::swapIndices(ipack, ninds);
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
static size_t blockSize(const std::tuple<std::shared_ptr<Indices>...>& pack)
|
||||
{
|
||||
|
@ -455,6 +462,12 @@ namespace MultiArrayHelper
|
|||
std::get<std::tuple_size<Pack>::value-1>(ipack) = nind;
|
||||
}
|
||||
|
||||
template <class Pack, class... Indices>
|
||||
static void swapIndices(Pack& ipack, const std::tuple<std::shared_ptr<Indices>...>& ninds)
|
||||
{
|
||||
std::get<0>(ipack) = std::get<0>(ninds);
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
static size_t blockSize(const std::tuple<std::shared_ptr<Indices>...>& pack)
|
||||
{
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace MultiArrayTools
|
|||
typedef ContainerIndex<T,typename SRanges::IndexType...> IType;
|
||||
|
||||
using MultiArrayBase<T,SRanges...>::operator();
|
||||
using MultiArrayBase<T,SRanges...>::operator[];
|
||||
|
||||
DEFAULT_MEMBERS(ConstSlice);
|
||||
|
||||
|
@ -60,7 +61,9 @@ namespace MultiArrayTools
|
|||
|
||||
using MultiArrayBase<T,SRanges...>::operator();
|
||||
using MutableMultiArrayBase<T,SRanges...>::operator();
|
||||
|
||||
using MultiArrayBase<T,SRanges...>::operator[];
|
||||
using MutableMultiArrayBase<T,SRanges...>::operator[];
|
||||
|
||||
DEFAULT_MEMBERS(Slice);
|
||||
|
||||
Slice(const std::shared_ptr<SRanges>&... ranges, T* data = nullptr);
|
||||
|
|
Loading…
Reference in a new issue