UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
if_then.hpp
1
42#ifndef UFO_CONTAINER_TREE_PREDICATE_IF_THEN_HPP
43#define UFO_CONTAINER_TREE_PREDICATE_IF_THEN_HPP
44
45// UFO
46#include <ufo/container/tree/predicate/filter.hpp>
47#include <ufo/utility/type_traits.hpp>
48
49// STL
50#include <type_traits>
51
52namespace ufo::pred
53{
54template <Filterable PredPre, Filterable PredPost>
55struct IfThen {
56 IfThen(PredPre const& pre, PredPost const& post) noexcept : pre(pre), post(post) {}
57
58 PredPre pre;
59 PredPost post;
60};
61
62template <Filterable PredPre, Filterable PredPost>
63[[nodiscard]] constexpr IfThen<std::remove_cvref_t<PredPre>,
64 std::remove_cvref_t<PredPost>>
65operator>>(PredPre&& pre, PredPost&& post) noexcept
66{
67 return IfThen(std::forward<PredPre>(pre), std::forward<PredPost>(post));
68}
69
70template <Filterable PredPre, Filterable PredPost>
71struct Filter<IfThen<PredPre, PredPost>> {
73
74 template <class Tree>
75 static constexpr void init(Pred& p, Tree const& t) noexcept
76 {
77 Filter<PredPre>::init(p.pre, t);
78 Filter<PredPost>::init(p.post, t);
79 }
80
81 template <class Value>
82 [[nodiscard]] static constexpr bool returnableValue(Pred const& p,
83 Value const& v) noexcept
84 {
85 return !Filter<PredPre>::returnableValue(p.pre, v) ||
87 }
88
89 template <class Tree>
90 [[nodiscard]] static constexpr bool returnable(Pred const& p, Tree const& t,
91 typename Tree::Node const& n) noexcept
92 {
93 return !Filter<PredPre>::returnable(p.pre, t, n) ||
94 Filter<PredPost>::returnable(p.post, t, n);
95 }
96
97 template <class Tree>
98 [[nodiscard]] static constexpr bool traversable(Pred const&, Tree const&,
99 typename Tree::Node const&) noexcept
100 {
101 // NOTE: This is not the same as the returnable check! If the pre-predicate
102 // is false, we can still traverse the subtree corresponding to the post-predicate.
103 return true;
104 }
105
106 template <class Tree>
107 [[nodiscard]] static constexpr bool returnableRay(Pred const& p, Tree const& t,
108 typename Tree::Node const& n,
109 typename Tree::Ray const& r) noexcept
110 {
111 return !Filter<PredPre>::returnableRay(p.pre, t, n, r) ||
112 Filter<PredPost>::returnableRay(p.post, t, n, r);
113 }
114
115 template <class Tree>
116 [[nodiscard]] static constexpr bool traversableRay(Pred const&, Tree const&,
117 typename Tree::Node const&,
118 typename Tree::Ray const&) noexcept
119 {
120 // NOTE: This is not the same as the returnable check! If the pre-predicate
121 // is false, we can still traverse the subtree corresponding to the post-predicate.
122 return true;
123 }
124};
125
126namespace detail
127{
128template <class T, class L, class R>
129struct contains_pred<T, IfThen<L, R>>
130 : std::disjunction<contains_pred<T, L>, contains_pred<T, R>> {
131};
132
133template <class T, class L, class R>
134struct contains_always_pred<T, IfThen<L, R>> : std::false_type {
135};
136} // namespace detail
137} // namespace ufo::pred
138
139#endif // UFO_CONTAINER_TREE_PREDICATE_IF_THEN_HPP
Utilizing curiously recurring template pattern (CRTP)
Definition tree.hpp:104