cnorxz/src/include/helper_tools.h

87 lines
2.5 KiB
C
Raw Normal View History

2017-11-20 20:53:48 +01:00
2017-11-20 21:00:52 +01:00
#ifndef __helper_tools_h__
#define __helper_tools_h__
2017-11-20 20:53:48 +01:00
#include "base_def.h"
2018-03-05 00:04:50 +01:00
#include "slice.h"
#include <ostream>
#include "pack_num.h"
2018-09-11 18:38:30 +02:00
#include <functional>
2017-11-20 20:53:48 +01:00
namespace MultiArrayTools
{
template <typename... T>
std::ostream& operator<<(std::ostream& out, const std::tuple<T...>& tp);
2017-11-20 20:53:48 +01:00
template <class RangeType>
auto getIndex(std::shared_ptr<RangeType> range)
-> std::shared_ptr<typename RangeType::IndexType>;
// only if 'RangeType' is defaultable and unique (Singleton)
template <class RangeType>
auto getIndex() -> std::shared_ptr<typename RangeType::IndexType>;
template <class... RangeTypes>
auto mkMulti(std::shared_ptr<RangeTypes>... ranges)
-> std::shared_ptr<MultiRange<RangeTypes...> >;
2018-09-16 16:35:46 +02:00
template <class Func, class... RangeTypes>
auto mkMapR(const Func& f, std::shared_ptr<RangeTypes>... ranges)
-> std::shared_ptr<MapRange<FunctionalMultiArray<typename Func::value_type,Func,RangeTypes...>,
RangeTypes...> >;
template <class Func, class... IndexTypes>
auto mkMapI(const Func& f, std::shared_ptr<IndexTypes>... indices)
-> decltype( getIndex( mkMapR( f, indices->range()... ) ) );
template <class... IndexTypes>
auto mkMIndex(std::shared_ptr<IndexTypes>... indices)
-> decltype( getIndex( mkMulti( indices.range()... ) ) );
2018-03-05 00:04:50 +01:00
template <class... RangeTypes>
auto mkMulti(std::tuple<std::shared_ptr<RangeTypes>...> rangesTuple)
-> MultiRange<RangeTypes...>;
template <class RangeFactory>
auto createExplicit(RangeFactory& rf)
-> std::shared_ptr<typename RangeFactory::oType>;
template <class RangeFactory>
auto createExplicit(std::shared_ptr<RangeFactory> rfp)
-> std::shared_ptr<typename RangeFactory::oType>;
template <class Range>
auto createRange(const std::vector<char>& cvec)
-> std::shared_ptr<Range>;
2018-08-05 18:45:20 +02:00
template <size_t N, class MArray>
auto prtr(const MArray& ma)
-> decltype(ma.template getRangePtr<N>());
2018-09-11 18:38:30 +02:00
template <class IndexType>
inline void For(const std::shared_ptr<IndexType>& ind, const std::function<void(void)>& ll)
{
for((*ind) = 0; ind->pos() != ind->max(); ++(*ind)){
ll();
}
}
2018-09-13 17:42:16 +02:00
template <class Index>
inline auto mkOp(const std::shared_ptr<Index>& i)
-> decltype(std::declval<FunctionalMultiArray<typename Index::MetaType,
identity<typename Index::MetaType>,typename Index::RangeType> >
().exec(i))
{
FunctionalMultiArray<typename Index::MetaType,
identity<typename Index::MetaType>,
typename Index::RangeType> fma(i->range());
return fma.exec(i);
}
2017-11-20 20:53:48 +01:00
}
2017-11-20 21:00:52 +01:00
2017-11-20 21:00:52 +01:00
#endif