Fishnet 2.0.1
Framework for Graph-Based Analysis of GIS Vector Data
Loading...
Searching...
No Matches
CompositePredicate.hpp
Go to the documentation of this file.
1#pragma once
2#include <ranges>
3#include <algorithm>
5
6namespace fishnet::util{
7
12template<typename... Types>
14public:
15 using predicate_type = std::function<bool(Types...)>;
16protected:
17 std::vector<predicate_type> predicates;
18
19 constexpr explicit CompositePredicate(predicate_type && predicate){
20 predicates.push_back(predicate);
21 }
22
23 constexpr explicit CompositePredicate(predicate_type predicate){
24 predicates.push_back(std::move(predicate));
25 }
26
27 constexpr CompositePredicate() = default;
28public:
29 constexpr void add(predicate_type && predicate) {
30 predicates.push_back(predicate);
31 }
32
33 constexpr void add(const predicate_type & predicate) {
34 predicates.push_back(std::move(predicate));
35 }
36
37 constexpr bool empty() const noexcept {
38 return predicates.empty();
39 }
40};
41
46template<typename... Types>
47class AllOfPredicate:public CompositePredicate<Types...>{
48private:
49 using Parent = CompositePredicate<Types...>;
50public:
51 constexpr AllOfPredicate()=default;
52
53 constexpr explicit AllOfPredicate(Parent::predicate_type && predicate):Parent(predicate){}
54
55 constexpr explicit AllOfPredicate(Parent::predicate_type predicate):Parent(predicate){}
56
57 constexpr bool operator()(Types... args) const noexcept{
58 return std::ranges::all_of(this->predicates,[... args = std::forward<Types>(args)](const auto & predicate){
59 return predicate(args...);
60 });
61 }
62};
63
68template<typename... Types>
69class AnyOfPredicate:public CompositePredicate<Types...>{
70private:
71 using Parent = CompositePredicate<Types...>;
72public:
73 constexpr AnyOfPredicate()=default;
74
75 constexpr explicit AnyOfPredicate(Parent::predicate_type && predicate):Parent(predicate){}
76
77 constexpr explicit AnyOfPredicate(Parent::predicate_type predicate):Parent(predicate){}
78
79 constexpr bool operator()(Types... args) const noexcept{
80 return std::ranges::any_of(this->predicates,[... args = std::forward<Types>(args)] (const auto & predicate){
81 return predicate(args...);
82 });
83 }
84};
85static_assert(util::Predicate<AnyOfPredicate<int>,int>);
86static_assert(util::BiPredicate<AllOfPredicate<int,double>,int,double>);
87}
Definition CompositePredicate.hpp:47
constexpr AllOfPredicate()=default
constexpr AllOfPredicate(Parent::predicate_type &&predicate)
Definition CompositePredicate.hpp:53
constexpr bool operator()(Types... args) const noexcept
Definition CompositePredicate.hpp:57
constexpr AllOfPredicate(Parent::predicate_type predicate)
Definition CompositePredicate.hpp:55
Definition CompositePredicate.hpp:69
constexpr bool operator()(Types... args) const noexcept
Definition CompositePredicate.hpp:79
constexpr AnyOfPredicate(Parent::predicate_type &&predicate)
Definition CompositePredicate.hpp:75
constexpr AnyOfPredicate(Parent::predicate_type predicate)
Definition CompositePredicate.hpp:77
constexpr AnyOfPredicate()=default
Definition CompositePredicate.hpp:13
std::vector< predicate_type > predicates
Definition CompositePredicate.hpp:17
constexpr void add(predicate_type &&predicate)
Definition CompositePredicate.hpp:29
constexpr bool empty() const noexcept
Definition CompositePredicate.hpp:37
constexpr CompositePredicate()=default
constexpr CompositePredicate(predicate_type &&predicate)
Definition CompositePredicate.hpp:19
std::function< bool(Types...)> predicate_type
Definition CompositePredicate.hpp:15
constexpr void add(const predicate_type &predicate)
Definition CompositePredicate.hpp:33
constexpr CompositePredicate(predicate_type predicate)
Definition CompositePredicate.hpp:23
Definition FunctionalConcepts.hpp:42
Definition FunctionalConcepts.hpp:36
Definition AlternativeKeyMap.hpp:4