@@ -21,23 +21,43 @@ struct rt_node {
21
21
rt_node const &) -> bool = default ;
22
22
};
23
23
24
- template <stdx::ct_string Name> struct ct_node : rt_node {
24
+ template <stdx::ct_string Type, stdx::ct_string Name, bool IsReference,
25
+ typename F, typename ... Ps>
26
+ struct ct_node : rt_node {
25
27
using is_node = void ;
28
+ using type_t =
29
+ decltype (stdx::ct_string_to_type<Type, sc::string_constant>());
30
+
26
31
using name_t =
27
32
decltype (stdx::ct_string_to_type<Name, sc::string_constant>());
28
- };
29
33
30
- template <stdx::ct_string Name, stdx::ct_string Type>
31
- static void log_name_func () {
32
- CIB_TRACE (" flow.{}({})" ,
33
- stdx::ct_string_to_type<Type, sc::string_constant>(),
34
- stdx::ct_string_to_type<Name, sc::string_constant>());
35
- }
34
+ constexpr static auto is_reference = IsReference;
35
+
36
+ constexpr static auto predicate = [] { return (Ps{}() and ...); };
37
+
38
+ constexpr static auto run_func = [] {
39
+ if (predicate ()) {
40
+ F{}();
41
+ }
42
+ };
43
+
44
+ constexpr static auto log_func = [] {
45
+ if (predicate ()) {
46
+ CIB_TRACE (" flow.{}({})" , type_t {}, name_t {});
47
+ }
48
+ };
49
+
50
+ constexpr ct_node () : rt_node{run_func, log_func} {}
51
+
52
+ constexpr auto operator +() const -> ct_node<Type, Name, false , F, Ps...> {
53
+ return {};
54
+ }
55
+ };
36
56
37
57
namespace detail {
38
- template <stdx::ct_string Name , stdx::ct_string Type , typename F>
58
+ template <stdx::ct_string Type , stdx::ct_string Name , typename F>
39
59
[[nodiscard]] constexpr auto make_node () {
40
- return ct_node<Name>{{. run = F{}, . log_name = log_name_func< Name, Type>} };
60
+ return ct_node<Type, Name, true , F>{ };
41
61
}
42
62
43
63
constexpr auto empty_func = []() {};
@@ -46,7 +66,7 @@ constexpr auto empty_func = []() {};
46
66
template <stdx::ct_string Name, typename F>
47
67
requires (stdx::is_function_object_v<F> and std::is_empty_v<F>)
48
68
[[nodiscard]] constexpr auto action (F const &) {
49
- return detail::make_node<Name, " action" , F>();
69
+ return detail::make_node<" action" , Name , F>();
50
70
}
51
71
52
72
template <stdx::ct_string Name> [[nodiscard]] constexpr auto action () {
@@ -58,7 +78,7 @@ template <stdx::ct_string Name> [[nodiscard]] constexpr auto step() {
58
78
}
59
79
60
80
template <stdx::ct_string Name> [[nodiscard]] constexpr auto milestone () {
61
- return detail::make_node<Name, " milestone" , decltype (detail::empty_func)>();
81
+ return detail::make_node<" milestone" , Name , decltype (detail::empty_func)>();
62
82
}
63
83
64
84
inline namespace literals {
@@ -75,4 +95,16 @@ template <stdx::ct_string S>
75
95
return milestone<S>();
76
96
}
77
97
} // namespace literals
98
+
99
+ template <typename P, stdx::ct_string Type, stdx::ct_string Name,
100
+ bool IsReference, typename F, typename ... Ps>
101
+ constexpr auto
102
+ make_runtime_conditional (P, ct_node<Type, Name, IsReference, F, Ps...>) {
103
+ if constexpr (IsReference) {
104
+ return ct_node<Type, Name, true , F, Ps...>{};
105
+ } else {
106
+ return ct_node<Type, Name, false , F, P, Ps...>{};
107
+ }
108
+ }
109
+
78
110
} // namespace flow
0 commit comments