$darkmode
filter.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020 Robert Bosch GmbH
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * SPDX-License-Identifier: Apache-2.0
17  */
22 #pragma once
23 #ifndef CLOE_COMPONENT_UTILITY_FILTER_HPP_
24 #define CLOE_COMPONENT_UTILITY_FILTER_HPP_
25 
26 #include <vector>
27 
28 namespace cloe {
29 namespace utility {
30 namespace filter {
31 
32 template <typename F, typename T>
33 F both(F first, F second) {
34  return [first, second](const T& o) { return first(o) && second(o); };
35 }
36 
37 template <typename F, typename T>
38 F one_of(F first, F second) {
39  return [first, second](const T& o) { return first(o) && second(o); };
40 }
41 
42 template <typename F, typename T>
43 F all_of(std::vector<F> fs) {
44  return [fs](const T& o) {
45  for (auto f : fs) {
46  if (!f(o)) {
47  return false;
48  }
49  }
50  return true;
51  };
52 }
53 
54 template <typename F, typename T>
55 F any_of(std::vector<F> fs) {
56  return [fs](const T& o) {
57  for (auto f : fs) {
58  if (f(o)) {
59  return true;
60  }
61  }
62  return false;
63  };
64 }
65 
66 } // namespace filter
67 } // namespace utility
68 } // namespace cloe
69 
70 #endif // CLOE_COMPONENT_UTILITY_FILTER_HPP_
Definition: coordinator.hpp:36
Definition: conf.hpp:65