UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
if_and_only_if.hpp
1
42#ifndef UFO_CONTAINER_TREE_PREDICATE_IF_AND_ONLY_IF_HPP
43#define UFO_CONTAINER_TREE_PREDICATE_IF_AND_ONLY_IF_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 PredLeft, Filterable PredRight>
55struct Iff {
56 Iff(PredLeft const& left, PredRight const& right) noexcept : left(left), right(right) {}
57
58 PredLeft left;
59 PredRight right;
60};
61
62template <Filterable PredLeft, Filterable PredRight>
63struct Filter<Iff<PredLeft, PredRight>> {
65
66 template <class Tree>
67 static constexpr void init(Pred& p, Tree const& t) noexcept
68 {
69 Filter<PredLeft>::init(p.left, t);
70 Filter<PredRight>::init(p.right, t);
71 }
72
73 template <class Value>
74 [[nodiscard]] static constexpr bool returnableValue(Pred const& p,
75 Value const& v) noexcept
76 {
77 return Filter<PredLeft>::returnableValue(p.left, v) ==
79 }
80
81 template <class Tree>
82 [[nodiscard]] static constexpr bool returnable(Pred const& p, Tree const& t,
83 typename Tree::Node const& n) noexcept
84 {
85 return Filter<PredLeft>::returnable(p.left, t, n) ==
86 Filter<PredRight>::returnable(p.right, t, n);
87 }
88
89 template <class Tree>
90 [[nodiscard]] static constexpr bool traversable(Pred const&, Tree const&,
91 typename Tree::Node const&) noexcept
92 {
93 // NOTE: This is not the same as the returnable check!
94 return true;
95 }
96
97 template <class Tree>
98 [[nodiscard]] static constexpr bool returnableRay(Pred const& p, Tree const& t,
99 typename Tree::Node const& n,
100 typename Tree::Ray const& r) noexcept
101 {
102 return Filter<PredLeft>::returnableRay(p.left, t, n, r) ==
103 Filter<PredRight>::returnableRay(p.right, t, n, r);
104 }
105
106 template <class Tree>
107 [[nodiscard]] static constexpr bool traversableRay(Pred const&, Tree const&,
108 typename Tree::Node const&,
109 typename Tree::Ray const&) noexcept
110 {
111 // NOTE: This is not the same as the returnable check!
112 return true;
113 }
114};
115
116namespace detail
117{
118template <Filterable T, Filterable L, Filterable R>
119struct contains_pred<T, Iff<L, R>>
120 : std::disjunction<contains_pred<T, L>, contains_pred<T, R>> {
121};
122
123template <Filterable T, Filterable L, Filterable R>
124struct contains_always_pred<T, Iff<L, R>> : std::false_type {
125};
126} // namespace detail
127} // namespace ufo::pred
128
129#endif // UFO_CONTAINER_TREE_PREDICATE_IF_AND_ONLY_IF_HPP
Utilizing curiously recurring template pattern (CRTP)
Definition tree.hpp:104