-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDimension_Swapper.hpp
More file actions
61 lines (53 loc) · 1.44 KB
/
Dimension_Swapper.hpp
File metadata and controls
61 lines (53 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#pragma once
#include <stack>
template<class Base, class T, int d>
struct Reverse_Swapper
{
Base& base;
std::stack<T>& indexes;
Reverse_Swapper<Base,T,d-1> nextR;
Reverse_Swapper(Base& base_, std::stack<T>& indexes_) : base(base_), indexes(indexes_), nextR(base_,indexes_) { }
auto& apply_indexes()
{
auto& to_return = nextR.apply_indexes()[indexes.top()];
indexes.pop();
return to_return;
}
};
template<class Base, class T>
struct Reverse_Swapper<Base,T,1>
{
Base& base;
std::stack<T>& indexes;
Reverse_Swapper(Base& base_, std::stack<T>& indexes_) : base(base_), indexes(indexes_) { }
auto& apply_indexes()
{
auto& to_return = base[indexes.top()];
indexes.pop();
return to_return;
}
};
template<class Base, class T, int d, int max=d>
struct Array_Index_Swapper
{
Base& base;
std::stack<T>& indexes;
Array_Index_Swapper<Base,T,d-1,max> nextD;
Array_Index_Swapper(Base& base_, std::stack<T>& indexes_) : base(base_), indexes(indexes_), nextD(base_, indexes_) { }
auto& operator[](T x)
{
indexes.push(x);
return nextD;
}
};
template<class Base, class T, int max>
struct Array_Index_Swapper<Base,T,1,max>
{
Base& base;
std::stack<T>& indexes;
Array_Index_Swapper(Base& base_, std::stack<T>& indexes_) : base(base_), indexes(indexes_) { }
auto& operator[](T x) {
indexes.push(x);
return Reverse_Swapper<Base,T,max>(base,indexes).apply_indexes();
}
};