UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
satisfies.hpp
1
42#ifndef UFO_CONTAINER_TREE_PREDICATE_SATISFIES_HPP
43#define UFO_CONTAINER_TREE_PREDICATE_SATISFIES_HPP
44
45// UFO
46#include <ufo/container/tree/predicate/filter.hpp>
47
48// STL
49#include <functional>
50
51namespace ufo::pred
52{
54 template <class... Args>
55 [[nodiscard]] constexpr bool operator()(Args&&...) const noexcept
56 {
57 return true;
58 }
59};
60
62 template <class... Args>
63 [[nodiscard]] constexpr bool operator()(Args&&...) const noexcept
64 {
65 return true;
66 }
67};
68
69template <class ReturnFun = SatisfiesDefaultReturnFun,
70 class TraverseFun = SatisfiesDefaultTraverseFun, bool Negated = false>
71struct Satisfies {
72 constexpr Satisfies() = default;
73
74 constexpr Satisfies(ReturnFun ret_fun) : ret_fun(ret_fun) {}
75
76 constexpr Satisfies(ReturnFun ret_fun, TraverseFun trav_fun)
77 : ret_fun(ret_fun), trav_fun(trav_fun)
78 {
79 }
80
81 ReturnFun ret_fun;
82 TraverseFun trav_fun;
83};
84
85template <class ReturnFun, class TraverseFun, bool Negated>
86[[nodiscard]] constexpr Satisfies<ReturnFun, TraverseFun, !Negated> operator!(
88{
89 return Satisfies<ReturnFun, TraverseFun, !Negated>(p.ret_fun, p.trav_fun);
90}
91
92template <class ReturnFun, class TraverseFun, bool Negated>
93struct Filter<Satisfies<ReturnFun, TraverseFun, Negated>> {
95
96 template <class Tree>
97 static constexpr void init(Pred&, Tree const&) noexcept
98 {
99 }
100
101 template <class Value>
102 [[nodiscard]] static constexpr bool returnableValue(Pred const& p,
103 Value const& v) noexcept
104 {
105 if constexpr (std::is_invocable_r_v<bool, ReturnFun, Value const&>) {
106 if constexpr (Negated) {
107 return !std::invoke_r<bool>(p.ret_fun, v);
108 } else {
109 return std::invoke_r<bool>(p.ret_fun, v);
110 }
111 } else {
112 return true;
113 }
114 }
115
116 template <class Tree>
117 [[nodiscard]] static constexpr bool returnable(Pred const& p, Tree const& t,
118 typename Tree::Node const& n) noexcept
119 {
120 if constexpr (std::is_invocable_r_v<bool, ReturnFun, Tree const&,
121 typename Tree::Node const&>) {
122 if constexpr (Negated) {
123 return !std::invoke_r<bool>(p.ret_fun, t, n);
124 } else {
125 return std::invoke_r<bool>(p.ret_fun, t, n);
126 }
127 } else {
128 return true;
129 }
130 }
131
132 template <class Tree>
133 [[nodiscard]] static constexpr bool traversable(Pred const& p, Tree const& t,
134 typename Tree::Node const& n) noexcept
135 {
136 if constexpr (std::is_invocable_r_v<bool, TraverseFun, Tree const&,
137 typename Tree::Node const&>) {
138 if constexpr (Negated) {
139 return !std::invoke_r<bool>(p.trav_fun, t, n);
140 } else {
141 return std::invoke_r<bool>(p.trav_fun, t, n);
142 }
143 } else {
144 return true;
145 }
146 }
147
148 template <class Tree>
149 [[nodiscard]] static constexpr bool returnableRay(Pred const& p, Tree const& t,
150 typename Tree::Node const& n,
151 typename Tree::Ray const&) noexcept
152 {
153 return returnable(p, t, n);
154 }
155
156 template <class Tree>
157 [[nodiscard]] static constexpr bool traversableRay(Pred const& p, Tree const& t,
158 typename Tree::Node const& n,
159 typename Tree::Ray const&) noexcept
160 {
161 return traversable(p, t, n);
162 }
163};
164} // namespace ufo::pred
165
166#endif // UFO_CONTAINER_TREE_PREDICATE_SATISFIES_HPP
Utilizing curiously recurring template pattern (CRTP)
Definition tree.hpp:104