AutoAPMS
Resilient Robot Mission Management
Loading...
Searching...
No Matches
container.hpp
1// Copyright 2024 Robin Müller
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <algorithm>
18#include <set>
19#include <vector>
20
21namespace auto_apms_util
22{
23
26
35template <typename ValueT, typename AllocatorT, template <typename T, class A> class ContainerT>
36bool contains(const ContainerT<ValueT, AllocatorT> & c, const ValueT & val)
37{
38 for (const ValueT & v : c)
39 if (v == val) return true;
40 return false;
41}
42
52template <typename KeyT, typename CompareT, typename AllocatorT>
53std::set<KeyT, CompareT, AllocatorT> getCommonElements(
54 std::set<KeyT, CompareT, AllocatorT> c1, std::set<KeyT, CompareT, AllocatorT> c2)
55{
56 std::set<KeyT, CompareT, AllocatorT> intersect;
57 std::set_intersection(c1.begin(), c1.end(), c2.begin(), c2.end(), std::inserter(intersect, intersect.begin()));
58 return intersect;
59}
60
69template <typename KeyT, typename AllocatorT>
70std::vector<KeyT, AllocatorT> getCommonElements(std::vector<KeyT, AllocatorT> c1, std::vector<KeyT, AllocatorT> c2)
71{
72 std::sort(c1.begin(), c1.end());
73 std::sort(c2.begin(), c2.end());
74 std::vector<KeyT, AllocatorT> intersect;
75 std::set_intersection(c1.begin(), c1.end(), c2.begin(), c2.end(), std::back_inserter(intersect));
76 return intersect;
77}
78
80
81} // namespace auto_apms_util
bool contains(const ContainerT< ValueT, AllocatorT > &c, const ValueT &val)
Check whether a particular container structure contains a value.
Definition container.hpp:36
std::set< KeyT, CompareT, AllocatorT > getCommonElements(std::set< KeyT, CompareT, AllocatorT > c1, std::set< KeyT, CompareT, AllocatorT > c2)
Assemble common elements of two sets.
Definition container.hpp:53
Fundamental helper classes and utility functions.