GCC Code Coverage Report


Directory: include/kumi/
File: include/kumi/algorithm/apply.hpp
Date: 2026-10-14 16:33:56
Exec Total Coverage
Lines: 6 6 100.0%
Functions: 13 13 100.0%
Branches: 4 4 100.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 F, typename T, std::size_t... I>
15 27 KUMI_HIDDEN_ABI constexpr decltype(auto) apply_(kumi::_::adl_tag_t, F&& f, T&& t, std::index_sequence<I...>)
16 {
17 8 if constexpr (kumi::concepts::empty_product_type<T>) return kumi::invoke(KUMI_FWD(f));
18 66 else return kumi::invoke(KUMI_FWD(f), get<I>(KUMI_FWD(t))...);
19 }
20 }
21
22 struct apply_t
23 {
24 template<typename Function, kumi::concepts::product_type T>
25 KUMI_ABI constexpr decltype(auto) operator()(Function&& f, T&& t) const
26 noexcept(kumi::_::supports_nothrow_apply<Function&&, T&&>)
27 requires(kumi::_::supports_apply<Function, T>)
28 {
29 5 if constexpr (kumi::concepts::record_type<T>) return (*this)(KUMI_FWD(f), kumi::values_of(KUMI_FWD(t)));
30
3/3
✓ Branch 1 taken 6 times.
✓ Branch 3 taken 2 times.
✓ Branch 6 taken 1 times.
15 else return apply_(kumi::_::adl_tag, KUMI_FWD(f), KUMI_FWD(t), kumi::function::indexes_for<T>{});
31 }
32 };
33
34 struct apply_field_t
35 {
36 template<typename Function, kumi::concepts::record_type R>
37 KUMI_ABI constexpr decltype(auto) operator()(Function&& f, R&& t) const
38 {
39
1/1
✓ Branch 1 taken 1 times.
1 return apply_(kumi::_::adl_tag, KUMI_FWD(f), KUMI_FWD(t), kumi::function::indexes_for<R>{});
40 }
41 };
42
43 //====================================================================================================================
44 /**
45 @ingroup kumi_transforms
46
47 @var apply
48 @brief Callable object invoking the callable object f with the elements of the product type unrolled as arguments.
49
50 `f` is applied on the underlying values when the input `t` is a record type.
51
52 @note This function does not take part in overload resolution if `f` can't be applied to the
53 elements of `t`.
54
55 @qualifier inline
56 @qualifier constexpr
57 @qualifier noexcept
58
59 @groupheader{Header file}
60 @code
61 #include <kumi/algorithm/apply.hpp>
62 @endcode
63
64 @groupheader{Call Signature}
65
66 @code
67 template<typename Function, product_type T>
68 constexpr decltype(auto) apply(Function && f, T && t) noexcept;
69 @endcode
70
71 @subgroupheader{Parameters}
72
73 - `f`: Callable object to be invoked
74 - `t`: Product Type whose elements are used as arguments to f
75
76 @subgroupheader{Return value}
77
78 - The value returned by f.
79
80 @groupheader{Helper type}
81
82 @snippet include/kumi/algorithm/apply.hpp apply_t
83
84 Computes the return type of a call to kumi::apply
85
86 @groupheader{Examples}
87
88 @tab_begin
89
90 @tab{Tuple}
91 @godbolt{doc/tuple/algo/apply.cpp}
92
93 @tab{Record}
94 @godbolt{doc/record/algo/apply.cpp}
95
96 @tab_end
97 **/
98 //====================================================================================================================
99 KUMI_VARIABLE_ABI constexpr apply_t apply{};
100
101 //====================================================================================================================
102 /**
103 @ingroup kumi_transforms
104
105 @var apply_field
106 @brief Callable object invoking the callable object f with the elements of the product type unrolled as arguments.
107
108 `f` is applied on the fields when the input `t` is a record type.
109
110 @note This function does not take part in overload resolution if `f` can't be applied to the
111 elements of `t`.
112
113 @qualifier inline
114 @qualifier constexpr
115 @qualifier noexcept
116
117 @groupheader{Header file}
118 @code
119 #include <kumi/algorithm/apply.hpp>
120 @endcode
121
122 @groupheader{Call Signature}
123
124 @code
125 template<typename Function, product_type T>
126 constexpr decltype(auto) apply_field(Function && f, T && t) noexcept;
127 @endcode
128
129 @subgroupheader{Parameters}
130
131 - `f`: Callable object to be invoked
132 - `t`: Product Type whose elements are used as arguments to f
133
134 @subgroupheader{Return value}
135
136 - The value returned by f.
137
138 @groupheader{Helper type}
139
140 @snippet include/kumi/algorithm/apply.hpp apply_field_t
141
142 Computes the return type of a call to kumi::apply_field
143
144 @groupheader{Example}
145
146 @subgroupheader{Record}
147 @godbolt{doc/record/algo/apply_field.cpp}
148 **/
149 //====================================================================================================================
150 KUMI_VARIABLE_ABI constexpr apply_field_t apply_field{};
151
152 namespace result
153 {
154 //! [apply_t]
155 template<typename Function, kumi::concepts::product_type T>
156 using apply_t = decltype(kumi::apply(std::declval<Function>(), std::declval<T>()));
157
158 template<typename Function, kumi::concepts::product_type T> struct apply
159 {
160 using type = kumi::result::apply_t<Function, T>;
161 };
162
163 //! [apply_t]
164
165 //! [apply_field_t]
166 template<typename Function, concepts::record_type R>
167 using apply_field_t = decltype(kumi::apply_field(std::declval<Function>(), std::declval<R>()));
168
169 template<typename Function, kumi::concepts::record_type R> struct apply_field
170 {
171 using type = kumi::result::apply_field_t<Function, R>;
172 };
173
174 //! [apply_field_t]
175
176 }
177 }
178