$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 
24 #include <vector>
25 
26 namespace cloe {
27 namespace utility {
28 namespace filter {
29 
30 template <typename F, typename T>
31 F both(F first, F second) {
32  return [first, second](const T& o) { return first(o) && second(o); };
33 }
34 
35 template <typename F, typename T>
36 F one_of(F first, F second) {
37  return [first, second](const T& o) { return first(o) && second(o); };
38 }
39 
40 template <typename F, typename T>
41 F all_of(std::vector<F> fs) {
42  return [fs](const T& o) {
43  for (auto f : fs) {
44  if (!f(o)) {
45  return false;
46  }
47  }
48  return true;
49  };
50 }
51 
52 template <typename F, typename T>
53 F any_of(std::vector<F> fs) {
54  return [fs](const T& o) {
55  for (auto f : fs) {
56  if (f(o)) {
57  return true;
58  }
59  }
60  return false;
61  };
62 }
63 
64 } // namespace filter
65 } // namespace utility
66 } // namespace cloe