GCC Code Coverage Report


Directory: include/kumi/
File: include/kumi/algorithm/find.hpp
Date: 2026-10-14 16:33:56
Exec Total Coverage
Lines: 6 6 100.0%
Functions: 18 18 100.0%
Branches: 8 10 80.0%

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 Pred, typename T, std::size_t... I>
15 36 KUMI_HIDDEN_ABI constexpr std::size_t locate_(kumi::_::adl_tag_t, Pred p, T&& t, std::index_sequence<I...>) noexcept
16 {
17 36 std::size_t index = kumi::size_v<T>;
18
8/10
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 16 times.
✓ Branch 7 taken 4 times.
✓ Branch 8 taken 12 times.
✓ Branch 10 taken 6 times.
✓ Branch 11 taken 6 times.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
264 ((kumi::invoke(p, get<I>(KUMI_FWD(t))) && ((index = I), true)) || ...);
19 36 return index;
20 }
21 }
22
23 struct locate_t
24 {
25 template<typename Pred, kumi::concepts::product_type T>
26 [[nodiscard]] KUMI_ABI constexpr std::size_t operator()(T&& t, Pred p) const noexcept
27 {
28 if constexpr (kumi::concepts::empty_product_type<T>) return 0;
29 9 else if constexpr (kumi::concepts::record_type<T>) return (*this)(kumi::values_of(KUMI_FWD(t)), p);
30 18 else return locate_(kumi::_::adl_tag, p, KUMI_FWD(t), kumi::function::indexes_for<T>{});
31 }
32 };
33
34 //====================================================================================================================
35 /**
36 @ingroup kumi_queries
37
38 @var locate
39 @brief Callable object returning the index of a value whose type satisfies a given predicate
40
41 On record types, this function operates as if the elements are ordered. The considered order is the order of
42 declaration.
43
44 @qualifier nodiscard
45 @qualifier inline
46 @qualifier constexpr
47 @qualifier noexcept
48
49 @groupheader{Header file}
50 @code
51 #include <kumi/algorithm/find.hpp>
52 @endcode
53
54 @groupheader{Call Signature}
55
56 @code
57 template<product_type T, typename Predicate>
58 constexpr auto locate(T && t, Pred p) noexcept;
59 @endcode
60
61 @subgroupheader{Parameters}
62
63 - `t`: Product Type to process
64 - `p`: Unary predicate. p must return a value convertible to `bool` for every element of t.
65
66 @subgroupheader{Return value}
67
68 - The integral index of the element inside `t` that matches the predicate, size_v<T> otherwise.
69
70 @groupheader{Examples}
71
72 @tab_begin
73
74 @tab{Tuple}
75 @godbolt{doc/tuple/algo/locate.cpp}
76
77 @tab{Record}
78 @godbolt{doc/record/algo/locate.cpp}
79
80 @tab_end
81 **/
82 //====================================================================================================================
83 KUMI_VARIABLE_ABI constexpr locate_t locate{};
84 }
85