CNORXZ
Container with Native Operation Routines and Expressions
Loading...
Searching...
No Matches
index_format.cc.h
Go to the documentation of this file.
1// -*- C++ -*-
12#ifndef __cxz_index_format_cc_h__
13#define __cxz_index_format_cc_h__
14
15#include "index_format.h"
16
17namespace CNORXZ
18{
19 /*=============+
20 | MFormat |
21 +=============*/
22
23 template <SizeT N>
24 constexpr MFormat<N>::MFormat(const Arr<UPos,N>& b) :
25 mB(b)
26 {}
27
28 template <SizeT N>
29 template <class FormatT>
30 constexpr MFormat<N>::MFormat(const FormatT& f)
31 {
32 CXZ_ASSERT(f.size() == N, "try to assign format of wrong dimension");
33 iter<0,N>( [&](auto i) { mB[i] = f[i].val(); }, NoF{} );
34 }
35
36 template <SizeT N>
38 {
39 return mB;
40 }
41
42 template <SizeT N>
43 constexpr decltype(auto) MFormat<N>::size() const
44 {
45 return CSizeT<N>{};
46 }
47
48 template <SizeT N>
49 template <SizeT I>
50 constexpr decltype(auto) MFormat<N>::get(CSizeT<I> i) const
51 {
52 return std::get<I>(mB);
53 }
54
55 template <SizeT N>
56 template <SizeT I>
57 constexpr decltype(auto) MFormat<N>::operator[](CSizeT<I> i) const
58 {
59 return get(i);
60 }
61
62
63 /*==============+
64 | GMFormat |
65 +==============*/
66
67 template <class... PosT>
69 mB(b)
70 {}
71
72 template <class... PosT>
74 mB(std::forward<Tuple<PosT...>>(b))
75 {}
76
77 template <class... PosT>
78 template <class FormatT>
80 {
81 CXZ_ASSERT(f.size() == size(), "try to assign format of wrong dimension");
82 iter<0,sizeof...(PosT)>( [&](auto i) { std::get<i>(mB) = f[i].val(); }, NoF{} );
83 }
84
85 template <class... PosT>
86 const Tuple<PosT...>& GMFormat<PosT...>::all() const
87 {
88 return mB;
89 }
90
91 template <class... PosT>
92 constexpr decltype(auto) GMFormat<PosT...>::size() const
93 {
94 return CSizeT<sizeof...(PosT)>{};
95 }
96
97 template <class... PosT>
98 template <SizeT I>
99 constexpr decltype(auto) GMFormat<PosT...>::get(CSizeT<I> i) const
100 {
101 return std::get<I>(mB);
102 }
103
104 template <class... PosT>
105 template <SizeT I>
106 constexpr decltype(auto) GMFormat<PosT...>::operator[](CSizeT<I> i) const
107 {
108 return get(i);
109 }
110
111 template <class... PosT>
112 constexpr decltype(auto) gmformat(const PosT&... ps)
113 {
114 return GMFormat(std::move(std::make_tuple(ps...)));
115 }
116
117 /*=============+
118 | YFormat |
119 +=============*/
120
121 template <class FormatT>
122 YFormat::YFormat(const FormatT& f) : mB(f.size())
123 {
124 // replace by check if integral constant
126 iter<0,f.size()>( [&](auto i) { mB[i] = f[i]; }, NoF{} );
127 }
128 else {
129 for(SizeT i = 0; i != mB.size(); ++i){
130 mB[i] = f[i];
131 }
132 }
133 }
134
135 template <SizeT I>
137 {
138 return mB[i];
139 }
140
141 template <SizeT I>
143 {
144 return mB[i];
145 }
146
147}
148
149#endif
#define CXZ_ASSERT(statement, errmsg)
Definition assert.h:40
constexpr GMFormat(const Tuple< PosT... > &b)
const Tuple< PosT... > & all() const
const Arr< UPos, N > & all() const
constexpr MFormat(const Arr< UPos, N > &b)
const UPos & get(CSizeT< I > i) const
YFormat(const Vector< UPos > &b)
const UPos & operator[](CSizeT< I > i) const
Index formats declaration.
uint64_t SizeT
Definition types.h:38
std::integral_constant< SizeT, N > CSizeT
Definition types.h:81
Sptr< Range > rangeCast(const RangePtr r)
std::tuple< T... > Tuple
Definition types.h:60
std::array< T, N > Arr
Definition types.h:45
constexpr decltype(auto) gmformat(const PosT &... ps)
constexpr decltype(auto) iter(const G &g, const F &f)
Definition iter.cc.h:34