-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperatable.hpp
144 lines (132 loc) · 3.53 KB
/
operatable.hpp
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#pragma once
#include"exp_function_binder.hpp"
#include"exp_function_series.hpp"
#include"exp_repeat.hpp"
#include"select_type.hpp"
#include <concepts>
#include<sstream>
namespace exp_operator
{
using namespace exp_bind;
using namespace exp_function_series;
template<class R, class T, class ...Args> requires std::invocable<R(T, Args...), T, Args...>
auto& bind_except_first(exp_function_binder<R(T, Args...)>& exp_binder, Args ... args)
{
exp_binder.reset_argc_stack();
++exp_binder.current_index;//skip node
exp_binder.bind_a_lot(std::forward<Args>(args)...);
exp_binder.reset_argc_stack();
return exp_binder;
}
template<class node, class exp_fn>
void deal_iter(exp_iterator<node>& iter, exp_fn& f)
{
auto bind_exp_binder = [&f](auto& value)
{
f.bind(value);
};
do_at(iter.first_node, f, iter.exp_index);
}
template<class node, class T>
T operator+ (exp_iterator<node>& iter, T const& val)
{
auto efb = exp_bind::bind([](T x, T y) {return x + y; });
deal_iter(iter, bind_except_first(efb, val));
return efb.apply_func();
}
template<class node, class T>
exp_iterator<node>& operator +=(exp_iterator<node>& iter, T const& val)
{
iter = iter + val;
return iter;
}
template<class node, class T>
T operator- (exp_iterator<node>& iter, T const& val)
{
auto efb = exp_bind::bind([](T x, T y) {return x - y; });
deal_iter(iter, bind_except_first(efb, val));
return efb.apply_func();
}
template<class node, class T>
exp_iterator<node>& operator -=(exp_iterator<node>& iter, T const& val)
{
iter = iter - val;
return iter;
}
template<class node, class T>
T operator* (exp_iterator<node>& iter, T const& val)
{
auto efb = exp_bind::bind([](T x, T y) {return x * y; });
deal_iter(iter, bind_except_first(efb, val));
return efb.apply_func();
}
template<class node, class T>
exp_iterator<node>& operator *=(exp_iterator<node>& iter, T const& val)
{
iter = iter * val;
return iter;
}
template<class node, class T>
T operator> (exp_iterator<node>& iter, T const& val)
{
auto efb = exp_bind::bind([](T x, T y)->bool {return x > y; });
deal_iter(iter, bind_except_first(efb, val));
return efb.apply_func();
}
template<class node, class T>
T operator< (exp_iterator<node>& iter, T const& val)
{
return !(iter > val);
}
template<class R, class STR>
requires std::is_same_v<std::decay_t<STR>, std::string>
std::istringstream& operator>>(std::istringstream& iss, exp_function_binder<R(STR)>& efb)
{
efb.bind(iss.str());
iss.clear();
return iss;
}
template<class R>
std::istream& operator>>(std::istream& is, exp_function_binder<R()>& efb)//input to a empty stack function is ...
{
return is;
}
template<class ...EFBS>
std::istream& operator>>(std::istream& is, series<EFBS...>& fl)
{
auto cinefb = [&is](auto& efb)
{
for (size_t i = 0; i < efb.argc_count(); ++i)
{
is >> efb;
}
};
do_at(*fl, cinefb, fl.series_index);
return is;
}
template<class ...EFBS>
std::istringstream& operator>>(std::istringstream& iss, series<EFBS...>& fl)
{
auto cinefb = [&iss](auto& efb)
{
for (size_t i = 0; i < efb.argc_count(); ++i)
{
iss >> efb;
}
};
do_at(*fl, cinefb, fl.series_index);
return iss;
}
template<class T, class U>
bool operator == (ref_wrapper<T> rw, U u)
{
if constexpr (requires(T x, U y)
{
{x == y}->std::same_as<bool>;
}
){
return rw.value == u;
}
return false;
}
}