Mjolnir Core
Core functionality of the Mjolnir API
parameter_pack.h
Go to the documentation of this file.
1 
7 
8 #pragma once
9 
11 
12 #include <concepts>
13 
14 
15 // === DECLARATION ====================================================================================================
16 
17 namespace mjolnir
18 {
21 
23 namespace internal
24 {
27 template <typename T_Type>
28 auto pack_type(T_Type...) -> T_Type;
29 
30 
31 } // namespace internal
33 
34 
40 template <auto... t_pack>
41 using PackType = decltype(internal::pack_type(t_pack...));
42 
43 
60 template <auto... t_pack, std::invocable<PackType<t_pack...>> T_Func>
61 [[nodiscard]] consteval auto pack_all(T_Func func) noexcept -> bool;
62 
63 
75 template <UST... t_pack>
76 [[nodiscard]] consteval auto pack_all_less(UST value) noexcept -> bool;
77 
78 
87 template <bool... t_pack>
88 [[nodiscard]] consteval auto pack_all_false() noexcept -> bool;
89 
90 
99 template <bool... t_pack>
100 [[nodiscard]] consteval auto pack_all_true() noexcept -> bool;
101 
102 
104 } // namespace mjolnir
105 
106 
107 // === DEFINITIONS ====================================================================================================
108 
109 
110 #include <algorithm>
111 #include <array>
112 
113 namespace mjolnir
114 {
115 // --------------------------------------------------------------------------------------------------------------------
116 
117 template <auto... t_pack, std::invocable<PackType<t_pack...>> T_Func>
118 [[nodiscard]] consteval auto pack_all(T_Func func) noexcept -> bool
119 {
120  using Type = PackType<t_pack...>;
121  constexpr UST size = sizeof...(t_pack);
122 
123  std::array<Type, size> a = {{t_pack...}};
124 
125  return std::ranges::all_of(a, func);
126 }
127 
128 
129 // --------------------------------------------------------------------------------------------------------------------
130 
131 template <UST... t_pack>
132 [[nodiscard]] consteval auto pack_all_less(UST value) noexcept -> bool
133 {
134  auto f = [value](UST e)
135  {
136  return e < value;
137  };
138 
139  return pack_all<t_pack...>(f);
140 }
141 
142 
143 // --------------------------------------------------------------------------------------------------------------------
144 
145 template <bool... t_pack>
146 [[nodiscard]] consteval auto pack_all_false() noexcept -> bool
147 {
148  auto f = [](bool e)
149  {
150  return ! e;
151  };
152 
153  return pack_all<t_pack...>(f);
154 }
155 
156 
157 // --------------------------------------------------------------------------------------------------------------------
158 
159 template <bool... t_pack>
160 [[nodiscard]] consteval auto pack_all_true() noexcept -> bool
161 {
162  auto f = [](bool e)
163  {
164  return e;
165  };
166 
167  return pack_all<t_pack...>(f);
168 }
169 
170 
171 } // namespace mjolnir
Defines the fundamental data types.
std::size_t UST
Unsigned integer type that is returned by sizeof operations.
Definition: fundamental_types.h:29
consteval auto pack_all_less(UST value) noexcept -> bool
Return true if all values of an unsigned integer parameter pack are less then a given value and false...
Definition: parameter_pack.h:132
consteval auto pack_all_false() noexcept -> bool
Return true if all values of an boolean parameter pack are false and false otherwise.
Definition: parameter_pack.h:146
consteval auto pack_all_true() noexcept -> bool
Return true if all values of an boolean parameter pack are true and false otherwise.
Definition: parameter_pack.h:160
decltype(internal::pack_type(t_pack...)) PackType
The type of a parameter pack that consist of values and not of types.
Definition: parameter_pack.h:41
consteval auto pack_all(T_Func func) noexcept -> bool
Return true if the passed function object returns true for all parameter pack values as input.
Definition: parameter_pack.h:118