| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | //====================================================================================================================== | ||
| 2 | /* | ||
| 3 | KUMI - Compact Tuple Tools | ||
| 4 | Copyright : KUMI Project Contributors | ||
| 5 | SPDX-License-Identifier: BSL-1.0 | ||
| 6 | */ | ||
| 7 | //====================================================================================================================== | ||
| 8 | #pragma once | ||
| 9 | |||
| 10 | namespace kumi | ||
| 11 | { | ||
| 12 | namespace _ | ||
| 13 | { | ||
| 14 | template<typename T, typename Pred, std::size_t... I> | ||
| 15 | 30 | KUMI_HIDDEN_ABI constexpr auto all_of_(kumi::_::adl_tag_t, T&& t, Pred p, std::index_sequence<I...>) | |
| 16 | { | ||
| 17 |
9/11✓ Branch 0 taken 4 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 9 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 7 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
|
184 | return (kumi::invoke(p, get<I>(KUMI_FWD(t))) && ...); |
| 18 | } | ||
| 19 | |||
| 20 | template<typename T, typename Pred, std::size_t... I> | ||
| 21 | 60 | KUMI_HIDDEN_ABI constexpr auto any_of_(kumi::_::adl_tag_t, T&& t, Pred p, std::index_sequence<I...>) | |
| 22 | { | ||
| 23 |
8/11✓ Branch 0 taken 2 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 9 times.
✓ Branch 8 taken 5 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 9 times.
|
300 | return (kumi::invoke(p, get<I>(KUMI_FWD(t))) || ...); |
| 24 | } | ||
| 25 | |||
| 26 | template<typename T, std::size_t... I> | ||
| 27 | 12 | KUMI_HIDDEN_ABI constexpr std::size_t count_(kumi::_::adl_tag_t, T&& t, std::index_sequence<I...>) | |
| 28 | { | ||
| 29 | 54 | return ((static_cast<bool>(get<I>(KUMI_FWD(t)))) + ... + 0ULL); | |
| 30 | } | ||
| 31 | |||
| 32 | template<typename Pred, typename T, std::size_t... I> | ||
| 33 | 20 | KUMI_HIDDEN_ABI constexpr std::size_t count_if_(kumi::_::adl_tag_t, T&& t, Pred p, std::index_sequence<I...>) | |
| 34 | { | ||
| 35 | 20 | [[maybe_unused]] constexpr std::size_t o = 1ULL; | |
| 36 | 20 | [[maybe_unused]] constexpr std::size_t z = 0ULL; | |
| 37 |
8/8✓ Branch 1 taken 4 times.
✓ Branch 2 taken 7 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 9 times.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 4 times.
✓ Branch 10 taken 4 times.
✓ Branch 11 taken 7 times.
|
160 | return ((kumi::invoke(p, get<I>(KUMI_FWD(t))) ? o : z) + ... + z); |
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | struct all_of_t | ||
| 42 | { | ||
| 43 | template<typename Pred, kumi::concepts::product_type T> | ||
| 44 | [[nodiscard]] KUMI_ABI constexpr auto operator()(T&& t, Pred p) const noexcept | ||
| 45 | { | ||
| 46 | if constexpr (kumi::concepts::empty_product_type<T>) return true; | ||
| 47 | 5 | else if constexpr (kumi::concepts::record_type<T>) return (*this)(kumi::values_of(KUMI_FWD(t)), p); | |
| 48 | else if constexpr (kumi::concepts::sized_product_type<T, 1>) return kumi::invoke(p, get<0>(KUMI_FWD(t))); | ||
| 49 | 15 | else return all_of_(kumi::_::adl_tag, KUMI_FWD(t), p, kumi::function::indexes_for<T>{}); | |
| 50 | } | ||
| 51 | |||
| 52 | template<kumi::concepts::product_type T> [[nodiscard]] KUMI_ABI constexpr auto operator()(T&& t) const noexcept | ||
| 53 | { | ||
| 54 | if constexpr (kumi::concepts::empty_product_type<T>) return true; | ||
| 55 | 2 | else if constexpr (kumi::concepts::record_type<T>) return (*this)(kumi::values_of(KUMI_FWD(t))); | |
| 56 | else if constexpr (kumi::concepts::sized_product_type<T, 1>) return !!get<0>(KUMI_FWD(t)); | ||
| 57 | 4 | else return (*this)(KUMI_FWD(t), kumi::function::identity); | |
| 58 | } | ||
| 59 | }; | ||
| 60 | |||
| 61 | struct any_of_t | ||
| 62 | { | ||
| 63 | template<typename Pred, kumi::concepts::product_type T> | ||
| 64 | [[nodiscard]] KUMI_ABI constexpr auto operator()(T&& t, Pred p) const noexcept | ||
| 65 | { | ||
| 66 | if constexpr (kumi::concepts::empty_product_type<T>) return true; | ||
| 67 | 10 | else if constexpr (kumi::concepts::record_type<T>) return (*this)(kumi::values_of(KUMI_FWD(t)), p); | |
| 68 | else if constexpr (kumi::concepts::sized_product_type<T, 1>) return kumi::invoke(p, get<0>(KUMI_FWD(t))); | ||
| 69 | 30 | else return any_of_(kumi::_::adl_tag, KUMI_FWD(t), p, kumi::function::indexes_for<T>{}); | |
| 70 | } | ||
| 71 | |||
| 72 | template<kumi::concepts::product_type T> [[nodiscard]] KUMI_ABI constexpr auto operator()(T&& t) const noexcept | ||
| 73 | { | ||
| 74 | if constexpr (kumi::concepts::empty_product_type<T>) return false; | ||
| 75 | 4 | else if constexpr (kumi::concepts::record_type<T>) return (*this)(kumi::values_of(KUMI_FWD(t))); | |
| 76 | else if constexpr (kumi::concepts::sized_product_type<T, 1>) return !!get<0>(KUMI_FWD(t)); | ||
| 77 | 8 | else return (*this)(KUMI_FWD(t), kumi::function::identity); | |
| 78 | } | ||
| 79 | }; | ||
| 80 | |||
| 81 | struct none_of_t : private kumi::any_of_t | ||
| 82 | { | ||
| 83 | template<typename Pred, kumi::concepts::product_type T> | ||
| 84 | [[nodiscard]] KUMI_ABI constexpr auto operator()(T&& t, Pred p) const noexcept | ||
| 85 | { | ||
| 86 | 11 | return !kumi::any_of_t::operator()(KUMI_FWD(t), p); | |
| 87 | } | ||
| 88 | |||
| 89 | template<kumi::concepts::product_type T> [[nodiscard]] KUMI_ABI constexpr auto operator()(T&& t) const noexcept | ||
| 90 | { | ||
| 91 | 4 | return !kumi::any_of_t::operator()(KUMI_FWD(t)); | |
| 92 | } | ||
| 93 | }; | ||
| 94 | |||
| 95 | struct count_if_t | ||
| 96 | { | ||
| 97 | template<typename Pred, kumi::concepts::product_type T> | ||
| 98 | [[nodiscard]] KUMI_ABI constexpr std::size_t operator()(T&& t, Pred p) const noexcept | ||
| 99 | { | ||
| 100 | if constexpr (kumi::concepts::empty_product_type<T>) return 0ULL; | ||
| 101 | 5 | else if constexpr (kumi::concepts::record_type<T>) return (*this)(values_of(KUMI_FWD(t)), p); | |
| 102 | 11 | else return count_if_(kumi::_::adl_tag, KUMI_FWD(t), p, kumi::function::indexes_for<T>{}); | |
| 103 | } | ||
| 104 | }; | ||
| 105 | |||
| 106 | struct count_t | ||
| 107 | { | ||
| 108 | template<kumi::concepts::product_type T> | ||
| 109 | [[nodiscard]] KUMI_ABI constexpr std::size_t operator()(T&& t) const noexcept | ||
| 110 | { | ||
| 111 | if constexpr (kumi::concepts::empty_product_type<T>) return 0ULL; | ||
| 112 | 3 | else if constexpr (kumi::concepts::record_type<T>) return (*this)(values_of(KUMI_FWD(t))); | |
| 113 | 7 | else return count_(kumi::_::adl_tag, KUMI_FWD(t), kumi::function::indexes_for<T>{}); | |
| 114 | } | ||
| 115 | }; | ||
| 116 | |||
| 117 | //==================================================================================================================== | ||
| 118 | /** | ||
| 119 | @ingroup kumi_queries | ||
| 120 | |||
| 121 | @var all_of | ||
| 122 | @brief Callable object checking if a unary predicate p returns true for every element of t. | ||
| 123 | |||
| 124 | On a record type, the function operates on the underlying elements of the fields. | ||
| 125 | |||
| 126 | @qualifier inline | ||
| 127 | @qualifier constexpr | ||
| 128 | @qualifier noexcept | ||
| 129 | |||
| 130 | @groupheader{Header file} | ||
| 131 | @code | ||
| 132 | #include <kumi/algorithm/predicates.hpp> | ||
| 133 | @endcode | ||
| 134 | |||
| 135 | @groupheader{Call Signature} | ||
| 136 | |||
| 137 | @code | ||
| 138 | template<product_type T, typename Pred> | ||
| 139 | constexpr auto all_of(T && t, Pred p) noexcept; | ||
| 140 | @endcode | ||
| 141 | |||
| 142 | @code | ||
| 143 | template<product_type T, typename Pred> | ||
| 144 | constexpr auto all_of(T && t) noexcept; | ||
| 145 | @endcode | ||
| 146 | |||
| 147 | @subgroupheader{Parameters} | ||
| 148 | |||
| 149 | - `t`: Product Type to process | ||
| 150 | - `p`: Unary predicate | ||
| 151 | |||
| 152 | @subgroupheader{Return value} | ||
| 153 | |||
| 154 | - The evaluation of `p(get<0>(t)) && ... && p(get<N-1>(t))` where `N` is the size of `t`. | ||
| 155 | |||
| 156 | @groupheader{Examples} | ||
| 157 | |||
| 158 | @tab_begin | ||
| 159 | |||
| 160 | @tab{Tuple} | ||
| 161 | @godbolt{doc/tuple/algo/all_of.cpp} | ||
| 162 | |||
| 163 | @tab{Record} | ||
| 164 | @godbolt{doc/record/algo/all_of.cpp} | ||
| 165 | |||
| 166 | @tab_end | ||
| 167 | **/ | ||
| 168 | //==================================================================================================================== | ||
| 169 | KUMI_VARIABLE_ABI constexpr all_of_t all_of{}; | ||
| 170 | |||
| 171 | //==================================================================================================================== | ||
| 172 | /** | ||
| 173 | @ingroup kumi_queries | ||
| 174 | |||
| 175 | @var any_of | ||
| 176 | @brief Callable object checking if a unary predicate p returns true for any element of t. | ||
| 177 | |||
| 178 | On a record type, the function operates on the underlying elements of the fields. | ||
| 179 | |||
| 180 | @qualifier inline | ||
| 181 | @qualifier constexpr | ||
| 182 | @qualifier noexcept | ||
| 183 | |||
| 184 | @groupheader{Header file} | ||
| 185 | @code | ||
| 186 | #include <kumi/algorithm/predicates.hpp> | ||
| 187 | @endcode | ||
| 188 | |||
| 189 | @groupheader{Call Signature} | ||
| 190 | |||
| 191 | @code | ||
| 192 | template<product_type T, typename Pred> | ||
| 193 | constexpr auto any_of(T && t, Pred p) noexcept; | ||
| 194 | @endcode | ||
| 195 | |||
| 196 | @code | ||
| 197 | template<product_type T, typename Pred> | ||
| 198 | constexpr auto any_of(T && t) noexcept; | ||
| 199 | @endcode | ||
| 200 | |||
| 201 | @subgroupheader{Parameters} | ||
| 202 | |||
| 203 | - `t`: Product Type to process | ||
| 204 | - `p`: Unary predicate | ||
| 205 | |||
| 206 | @subgroupheader{Return value} | ||
| 207 | |||
| 208 | - The evaluation of `p(get<0>(t)) || ... || p(get<N-1>(t))` where `N` is the size of `t`. | ||
| 209 | |||
| 210 | @groupheader{Examples} | ||
| 211 | |||
| 212 | @tab_begin | ||
| 213 | |||
| 214 | @tab{Tuple} | ||
| 215 | @godbolt{doc/tuple/algo/any_of.cpp} | ||
| 216 | |||
| 217 | @tab{Record} | ||
| 218 | @godbolt{doc/record/algo/any_of.cpp} | ||
| 219 | |||
| 220 | @tab_end | ||
| 221 | **/ | ||
| 222 | //==================================================================================================================== | ||
| 223 | KUMI_VARIABLE_ABI constexpr any_of_t any_of{}; | ||
| 224 | |||
| 225 | //==================================================================================================================== | ||
| 226 | /** | ||
| 227 | @ingroup kumi_queries | ||
| 228 | |||
| 229 | @var none_of | ||
| 230 | @brief Callable object checking if a unary predicate p does not return true for any element in t. | ||
| 231 | |||
| 232 | On a record type, the function operates on the underlying elements of the fields. | ||
| 233 | |||
| 234 | @qualifier inline | ||
| 235 | @qualifier constexpr | ||
| 236 | @qualifier noexcept | ||
| 237 | |||
| 238 | @groupheader{Header file} | ||
| 239 | @code | ||
| 240 | #include <kumi/algorithm/predicates.hpp> | ||
| 241 | @endcode | ||
| 242 | |||
| 243 | @groupheader{Call Signature} | ||
| 244 | |||
| 245 | @code | ||
| 246 | template<product_type T, typename Pred> | ||
| 247 | constexpr auto none_of(T && t, Pred p) noexcept; | ||
| 248 | @endcode | ||
| 249 | |||
| 250 | @code | ||
| 251 | template<product_type T, typename Pred> | ||
| 252 | constexpr auto none_of(T && t) noexcept; | ||
| 253 | @endcode | ||
| 254 | |||
| 255 | @subgroupheader{Parameters} | ||
| 256 | |||
| 257 | - `t`: Product Type to process | ||
| 258 | - `p`: Unary predicate | ||
| 259 | |||
| 260 | @subgroupheader{Return value} | ||
| 261 | |||
| 262 | - The evaluation of `!any_of(t,p)`. | ||
| 263 | |||
| 264 | @groupheader{Examples} | ||
| 265 | |||
| 266 | @tab_begin | ||
| 267 | |||
| 268 | @tab{Tuple} | ||
| 269 | @godbolt{doc/tuple/algo/none_of.cpp} | ||
| 270 | |||
| 271 | @tab{Record} | ||
| 272 | @godbolt{doc/record/algo/none_of.cpp} | ||
| 273 | |||
| 274 | @tab_end | ||
| 275 | **/ | ||
| 276 | //==================================================================================================================== | ||
| 277 | KUMI_VARIABLE_ABI constexpr none_of_t none_of{}; | ||
| 278 | |||
| 279 | //==================================================================================================================== | ||
| 280 | /** | ||
| 281 | @ingroup kumi_queries | ||
| 282 | |||
| 283 | @var count_if | ||
| 284 | @brief Callable object counting the number of elements of t satisfying predicates p. | ||
| 285 | |||
| 286 | On a record type, the function operates on the underlying elements of the fields. | ||
| 287 | |||
| 288 | @qualifier inline | ||
| 289 | @qualifier constexpr | ||
| 290 | @qualifier noexcept | ||
| 291 | |||
| 292 | @groupheader{Header file} | ||
| 293 | @code | ||
| 294 | #include <kumi/algorithm/predicates.hpp> | ||
| 295 | @endcode | ||
| 296 | |||
| 297 | @groupheader{Call Signature} | ||
| 298 | |||
| 299 | @code | ||
| 300 | template<product_type T, typename Pred> | ||
| 301 | constexpr auto count_if(T && t, Pred p) noexcept; | ||
| 302 | @endcode | ||
| 303 | |||
| 304 | @subgroupheader{Parameters} | ||
| 305 | |||
| 306 | - `t`: Product Type to process | ||
| 307 | - `p`: Unary predicate | ||
| 308 | |||
| 309 | @subgroupheader{Return value} | ||
| 310 | |||
| 311 | - Number of elements satisfying the condition. | ||
| 312 | |||
| 313 | @groupheader{Examples} | ||
| 314 | |||
| 315 | @tab_begin | ||
| 316 | |||
| 317 | @tab{Tuple} | ||
| 318 | @godbolt{doc/tuple/algo/count_if.cpp} | ||
| 319 | |||
| 320 | @tab{Record} | ||
| 321 | @godbolt{doc/record/algo/count_if.cpp} | ||
| 322 | |||
| 323 | @tab_end | ||
| 324 | **/ | ||
| 325 | //==================================================================================================================== | ||
| 326 | KUMI_VARIABLE_ABI constexpr count_if_t count_if{}; | ||
| 327 | |||
| 328 | //==================================================================================================================== | ||
| 329 | /** | ||
| 330 | @ingroup kumi_queries | ||
| 331 | |||
| 332 | @var count | ||
| 333 | @brief Callable object counting the number of elements of t not equivalent to false. | ||
| 334 | |||
| 335 | On a record type, the function operates on the underlying elements of the fields. | ||
| 336 | |||
| 337 | @qualifier inline | ||
| 338 | @qualifier constexpr | ||
| 339 | @qualifier noexcept | ||
| 340 | |||
| 341 | @groupheader{Header file} | ||
| 342 | @code | ||
| 343 | #include <kumi/algorithm/predicates.hpp> | ||
| 344 | @endcode | ||
| 345 | |||
| 346 | @groupheader{Call Signature} | ||
| 347 | |||
| 348 | @code | ||
| 349 | template<product_type T> | ||
| 350 | constexpr auto count(T && t) noexcept; | ||
| 351 | @endcode | ||
| 352 | |||
| 353 | @subgroupheader{Parameters} | ||
| 354 | |||
| 355 | - `t`: Product Type to process | ||
| 356 | |||
| 357 | @subgroupheader{Return value} | ||
| 358 | |||
| 359 | - Number of elements not equivalent to `false`. | ||
| 360 | |||
| 361 | @groupheader{Examples} | ||
| 362 | |||
| 363 | @tab_begin | ||
| 364 | |||
| 365 | @tab{Tuple} | ||
| 366 | @godbolt{doc/tuple/algo/count.cpp} | ||
| 367 | |||
| 368 | @tab{Record} | ||
| 369 | @godbolt{doc/record/algo/count.cpp} | ||
| 370 | |||
| 371 | @tab_end | ||
| 372 | **/ | ||
| 373 | //==================================================================================================================== | ||
| 374 | KUMI_VARIABLE_ABI constexpr count_t count{}; | ||
| 375 | } | ||
| 376 |