CNORXZ
Container with Native Operation Routines and Expressions
Loading...
Searching...
No Matches
op_utility.cc.h
Go to the documentation of this file.
1// -*- C++ -*-
12#ifndef __cxz_op_utility_cc_h__
13#define __cxz_op_utility_cc_h__
14
15#include "op_utility.h"
16#include "xpr/pos_type.h"
17
18namespace CNORXZ
19{
20 template <SizeT I, class PosT>
21 constexpr decltype(auto) pos_get(const PosT& pos)
22 {
23 static_assert(I < static_pos_size<PosT>::value, "index out of range");
24 if constexpr(I == 0){
25 return pos;
26 }
27 else {
28 return pos_get<I-1>(pos.next());
29 }
30 }
31
32 template <SizeT J, SizeT I, SizeT... Is>
33 constexpr SizeT sum_index_sequence(std::index_sequence<I,Is...> is)
34 {
35 static_assert(J < sizeof...(Is)+1, "index out of range");
36 if constexpr(J == 0){
37 return 0;
38 }
39 else {
40 return sum_index_sequence<J-1>(std::index_sequence<Is...>{}) + I;
41 }
42 }
43
44 template <class F, class PosT, class OpTuple, class OpSizes, SizeT... Is>
45 inline auto pos_unpack_args_i(const F& f, const PosT& pos, const OpTuple& args,
46 OpSizes opsizes, std::index_sequence<Is...> is)
47 {
48 return f(std::get<Is>(args)(pos_get<sum_index_sequence<Is>(opsizes)>(pos))...);
49 }
50
51 template <class F, class PosT, class... Ops>
52 inline auto pos_unpack_args(const F& f, const PosT& pos, const Tuple<Ops...>& args)
53 {
54 static_assert(is_pos_type<PosT>::value, "got non-pos-type");
55 static_assert((is_operation<Ops>::value and ...), "got non-operation type");
56 typedef std::make_index_sequence<sizeof...(Ops)> Idxs;
57 typedef std::index_sequence<op_size<Ops>::value...> OpSizes;
58 return pos_unpack_args_i(f, pos, args, OpSizes{}, Idxs{});
59 }
60
61}
62
63#endif
constexpr decltype(auto) pos_get(const PosT &pos)
uint64_t SizeT
Definition types.h:38
constexpr SizeT sum_index_sequence(std::index_sequence< I, Is... > is)
auto pos_unpack_args_i(const F &f, const PosT &pos, const OpTuple &args, OpSizes opsizes, std::index_sequence< Is... > is)
Sptr< Range > rangeCast(const RangePtr r)
std::tuple< T... > Tuple
Definition types.h:60
auto pos_unpack_args(const F &f, const PosT &pos, const Tuple< Ops... > &args)
Operation utilities declarations.
Position types declarations.