-
Notifications
You must be signed in to change notification settings - Fork 0
/
operation_stack.hpp
77 lines (66 loc) · 2.21 KB
/
operation_stack.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
#pragma once
#include"get_nth_element.hpp"
#include"index.hpp"
#include"idx.hpp"
#include<tuple>
namespace nuf
{
template<auto... Ts>
struct operation_stack
{
constexpr operation_stack() {/*Doesn't do anything*/ }
constexpr auto invoke_all()
{
(..., Ts()); // doesn't return anything
}
template<auto I>
constexpr auto and_then(nuf::idx<I>)
{
return nuf::get_nth_element<I>(Ts...)();
}
template<auto I>
constexpr auto invoke(nuf::index<I>)
{
nuf::get_nth_element<I>(Ts...)();
}
template<auto I>
constexpr auto get_n_return(nuf::index<I>)
{
return nuf::get_nth_element<I>(Ts...)();
}
constexpr auto get_all_returns()
{
auto tuple_lambdas = std::make_tuple(Ts...);
return [&] <std::size_t... indexes>(std::index_sequence<indexes...>)
{
// return std::tuple{(nuf::get_nth_element<indexes>(Ts)())...};
return std::tuple{(std::get<indexes>(tuple_lambdas)())...};
}(std::make_index_sequence < sizeof...(Ts)>{});
}
template<auto lambda, auto I>
struct lambda_wrapper
{
template<auto... lambdas>
constexpr auto and_then()
{
return nuf::dummy_type{};
}
}
template<auto I>
constexpr auto pipe() -> decltype(auto)
{
// so we want to go through the lambdas calling each one with, could do something like.
// lambda_wrapper<get_nth_element<0>(Ts...), I>{}.and_then<get_nth_element<indexes>(Ts...)>();
return[&]<std::size_t... indexes>(std::index_sequence<indexes...>)
{
// return (get_nth_element<indexes>(Ts...)(I)...);
return lambda_wrapper<nuf::get_nth_element<0>(Ts...), I>{}.and_then<nuf::get_nth_element<indexes>(Ts...)...>().val;
}/*(std::make_index_sequence<sizeof...(Ts)>{})*/;
}
template<auto I>
constexpr auto operator[](nuf::index<I>)
{
return nuf::get_nth_element<I>(Ts...);
}
};
} // namespace nuf