ThreadSchedule 3.0.0
Modern C++ thread management library
Loading...
Searching...
No Matches
query_facade_mixin.hpp
Go to the documentation of this file.
1#pragma once
2
8
9#include <cstddef>
10#include <optional>
11#include <type_traits>
12#include <utility>
13#include <vector>
14
16{
17
30template <typename Derived>
32{
33 auto
34 self() const -> Derived const&
35 {
36 return static_cast<Derived const&>(*this);
37 }
38
39public:
40 template <typename Predicate>
41 [[nodiscard]] auto
43 {
44 return self().query().filter(std::forward<Predicate>(pred));
45 }
46
47 [[nodiscard]] auto
48 count() const -> size_t
49 {
50 return self().query().count();
51 }
52
53 [[nodiscard]] auto
54 empty() const -> bool
55 {
56 return self().query().empty();
57 }
58
59 template <typename Fn>
60 void
61 for_each(Fn&& fn) const
62 {
63 self().query().for_each(std::forward<Fn>(fn));
64 }
65
66 template <typename Predicate, typename Fn>
67 void
68 apply(Predicate&& pred, Fn&& fn) const
69 {
70 self().query().filter(std::forward<Predicate>(pred)).for_each(std::forward<Fn>(fn));
71 }
72
73 template <typename Fn>
74 [[nodiscard]] auto
75 map(Fn&& fn) const -> std::vector<std::invoke_result_t<Fn, registered_thread_info_backend const&>>
76 {
77 return self().query().map(std::forward<Fn>(fn));
78 }
79
80 template <typename Predicate>
81 [[nodiscard]] auto
82 find_if(Predicate&& pred) const -> std::optional<registered_thread_info_backend>
83 {
84 return self().query().find_if(std::forward<Predicate>(pred));
85 }
86
87 template <typename Predicate>
88 [[nodiscard]] auto
89 any(Predicate&& pred) const -> bool
90 {
91 return self().query().any(std::forward<Predicate>(pred));
92 }
93
94 template <typename Predicate>
95 [[nodiscard]] auto
96 all(Predicate&& pred) const -> bool
97 {
98 return self().query().all(std::forward<Predicate>(pred));
99 }
100
101 template <typename Predicate>
102 [[nodiscard]] auto
103 none(Predicate&& pred) const -> bool
104 {
105 return self().query().none(std::forward<Predicate>(pred));
106 }
107
108 [[nodiscard]] auto
109 take(size_t n) const
110 {
111 return self().query().take(n);
112 }
113
114 [[nodiscard]] auto
115 skip(size_t n) const
116 {
117 return self().query().skip(n);
118 }
119};
120
121} // namespace threadschedule::detail
CRTP mixin that provides functional-style query facade methods.
auto none(Predicate &&pred) const -> bool
auto any(Predicate &&pred) const -> bool
auto all(Predicate &&pred) const -> bool
void apply(Predicate &&pred, Fn &&fn) const
auto map(Fn &&fn) const -> std::vector< std::invoke_result_t< Fn, registered_thread_info_backend const & > >
auto find_if(Predicate &&pred) const -> std::optional< registered_thread_info_backend >
Aggregates multiple thread_registry_backend instances into a single queryable view.
Native thread metadata and lifecycle-safe control blocks.