20
20
#include < map>
21
21
#include < string>
22
22
#include < unordered_map>
23
+ #include < unordered_set>
23
24
#include < vector>
24
25
25
26
namespace ros2_control
@@ -36,7 +37,8 @@ namespace ros2_control
36
37
template <typename Container, typename T>
37
38
[[nodiscard]] auto get_item_iterator (const Container & container, const T & item)
38
39
{
39
- if constexpr (std::is_same_v<Container, std::vector<T>>)
40
+ if constexpr (
41
+ std::is_same_v<Container, std::vector<T>> || std::is_same_v<Container, std::unordered_set<T>>)
40
42
{
41
43
return std::find (container.begin (), container.end (), item);
42
44
}
@@ -52,10 +54,11 @@ template <typename Container, typename T>
52
54
using is_map = std::is_same<Container, std::map<T, typename Container::mapped_type>>;
53
55
using is_unordered_map =
54
56
std::is_same<Container, std::unordered_map<T, typename Container::mapped_type>>;
57
+ using is_unordered_set = std::is_same<Container, std::unordered_set<T>>;
55
58
// Handle unsupported container types
56
59
static_assert (
57
- is_vector::value || is_map::value || is_unordered_map::value,
58
- " Only std::vector, std::map and std::unordered_map are supported." );
60
+ is_vector::value || is_map::value || is_unordered_map::value || is_unordered_set::value ,
61
+ " Only std::vector, std::unordered_set, std:: map and std::unordered_map are supported." );
59
62
}
60
63
}
61
64
@@ -175,6 +178,22 @@ template <typename Container>
175
178
return std::adjacent_find (container.cbegin (), container.cend ()) == container.cend ();
176
179
}
177
180
181
+ // Create a function that checks that two containers do not have any common items
182
+ /* *
183
+ * @brief Check if the two containers have no common items.
184
+ * @param container1 The first container to search in.
185
+ * @param container2 The second container to search in.
186
+ * @return True if the two containers have no common items, false otherwise.
187
+ */
188
+ template <typename Container1, typename Container2>
189
+ [[nodiscard]] bool has_no_common_items (const Container1 & container1, const Container2 & container2)
190
+ {
191
+ return std::none_of (
192
+ container1.cbegin (), container1.cend (),
193
+ [&container2](const typename Container1::value_type & item)
194
+ { return has_item (container2, item); });
195
+ }
196
+
178
197
} // namespace ros2_control
179
198
180
199
#endif // HARDWARE_INTERFACE__HELPERS_HPP_
0 commit comments