UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
exists.hpp
1
42#ifndef UFO_CONTAINER_TREE_PREDICATE_EXISTS_HPP
43#define UFO_CONTAINER_TREE_PREDICATE_EXISTS_HPP
44
45// UFO
46#include <ufo/container/tree/predicate/filter.hpp>
47
48namespace ufo::pred
49{
50
51template <bool Negated = false>
52struct Exists {
53};
54
55template <bool Negated>
56[[nodiscard]] constexpr Exists<!Negated> operator!(Exists<Negated> const&) noexcept
57{
58 return Exists<!Negated>{};
59}
60
61static constexpr inline Exists<false> const exists;
62
63template <bool Negated>
64struct Filter<Exists<Negated>> {
65 using Pred = Exists<Negated>;
66
67 template <class Tree>
68 static constexpr void init(Pred&, Tree const&) noexcept
69 {
70 }
71
72 template <class Value>
73 [[nodiscard]] static constexpr bool returnableValue(Pred const&, Value const&) noexcept
74 {
75 return true;
76 }
77
78 template <class Tree>
79 [[nodiscard]] static constexpr bool returnable(Pred const&, Tree const& t,
80 typename Tree::Node const& n) noexcept
81 {
82 if constexpr (Negated) {
83 return !t.exists(n);
84 } else {
85 return t.exists(n);
86 }
87 }
88
89 template <class Tree>
90 [[nodiscard]] static constexpr bool traversable(Pred const&, Tree const& t,
91 typename Tree::Node const& n) noexcept
92 {
93 if constexpr (Negated) {
94 return true;
95 } else {
96 return t.isParent(n.index);
97 }
98 }
99
100 template <class Tree>
101 [[nodiscard]] static constexpr bool returnableRay(Pred const& p, Tree const& t,
102 typename Tree::Node const& n,
103 typename Tree::Ray const&) noexcept
104 {
105 return returnable(p, t, n);
106 }
107
108 template <class Tree>
109 [[nodiscard]] static constexpr bool traversableRay(Pred const& p, Tree const& t,
110 typename Tree::Node const& n,
111 typename Tree::Ray const&) noexcept
112 {
113 return traversable(p, t, n);
114 }
115};
116} // namespace ufo::pred
117
118#endif // UFO_CONTAINER_TREE_PREDICATE_EXISTS_HPP
Utilizing curiously recurring template pattern (CRTP)
Definition tree.hpp:104
bool isParent(NodeType node) const
Checks if the node is a parent (i.e., has children).
Definition tree.hpp:1308