GCC Code Coverage Report


Directory: include/kumi/
File: include/kumi/algorithm/push_pop.hpp
Date: 2026-10-14 16:33:56
Exec Total Coverage
Lines: 10 10 100.0%
Functions: 20 20 100.0%
Branches: 12 12 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 T, typename V, std::size_t... I>
15 32 KUMI_HIDDEN_ABI constexpr auto push_front_(kumi::_::adl_tag_t, T&& t, V&& v, std::index_sequence<I...>)
16 {
17 68 return kumi::builder<T>::make(KUMI_FWD(v), get<I>(KUMI_FWD(t))...);
18 }
19
20 template<typename T, typename V, std::size_t... I>
21 32 KUMI_HIDDEN_ABI constexpr auto push_back_(kumi::_::adl_tag_t, T&& t, V&& v, std::index_sequence<I...>)
22 {
23 68 return kumi::builder<T>::make(get<I>(KUMI_FWD(t))..., KUMI_FWD(v));
24 }
25 }
26
27 struct push_front_t
28 {
29 template<kumi::concepts::product_type T, typename V>
30 [[nodiscard]] KUMI_ABI constexpr auto operator()(T&& t, V&& v) const
31 {
32
6/6
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 16 taken 1 times.
16 return push_front_(kumi::_::adl_tag, KUMI_FWD(t), KUMI_FWD(v), kumi::function::indexes_for<T>{});
33 }
34 };
35
36 struct pop_front_t
37 {
38 template<kumi::concepts::product_type T> [[nodiscard]] KUMI_ABI constexpr auto operator()(T&& t) const
39 {
40 5 if constexpr (kumi::concepts::empty_product_type<T>) return kumi::builder<T>::make();
41 14 else return kumi::_::builder(KUMI_FWD(t), kumi::function::shift_index_sequence<1, kumi::size_v<T> - 1>{});
42 }
43 };
44
45 struct push_back_t
46 {
47 template<kumi::concepts::product_type T, typename V>
48 [[nodiscard]] KUMI_ABI constexpr auto operator()(T&& t, V&& v) const
49 {
50
6/6
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 16 taken 2 times.
16 return push_back_(kumi::_::adl_tag, KUMI_FWD(t), KUMI_FWD(v), kumi::function::indexes_for<T>{});
51 }
52 };
53
54 struct pop_back_t
55 {
56 template<kumi::concepts::product_type T> [[nodiscard]] KUMI_ABI constexpr auto operator()(T&& t) const
57 {
58 6 if constexpr (kumi::concepts::empty_product_type<T>) return kumi::builder<T>::make();
59 14 else return kumi::_::builder(KUMI_FWD(t), std::make_index_sequence<kumi::size_v<T> - 1>{});
60 }
61 };
62
63 //====================================================================================================================
64 /**
65 @ingroup kumi_generators
66
67 @var push_front
68 @brief Callable object constructing a product type by adding a value `v` at the beginning of `t`.
69
70 On record types, this function operates on elements as if they were ordered. The considered order is the order
71 of declaration.
72
73 @qualifier nodiscard
74 @qualifier inline
75 @qualifier constexpr
76
77 @groupheader{Header file}
78 @code
79 #include <kumi/algorithm/push_pop.hpp>
80 @endcode
81
82 @groupheader{Call Signature}
83
84 @code
85 template<product_type T, typename V>
86 constexpr auto push_front(T && t, V && v);
87 @endcode
88
89 @subgroupheader{Parameters}
90
91 - `t`: Base product type
92 - `v`: Value to insert in front of `t`
93
94 @subgroupheader{Return value}
95
96 - A product type composed of `v` followed by all elements of `t` in order.
97
98 @groupheader{Helper type}
99
100 @snippet include/kumi/algorithm/push_pop.hpp push_front_t
101
102 Computes the return type of a call to kumi::push_front
103
104 @groupheader{Examples}
105
106 @tab_begin
107
108 @tab{Tuple}
109 @godbolt{doc/tuple/algo/push_front.cpp}
110
111 @tab{Record}
112 @godbolt{doc/record/algo/push_front.cpp}
113
114 @tab_end
115 **/
116 //====================================================================================================================
117 KUMI_VARIABLE_ABI constexpr push_front_t push_front{};
118
119 //====================================================================================================================
120 /**
121 @ingroup kumi_generators
122
123 @var pop_front
124 @brief Callable object removing the first (if any) element of `t`.
125
126 On record types, this function operates on elements as if they were ordered. The considered order is the order
127 of declaration.
128
129 @qualifier nodiscard
130 @qualifier inline
131 @qualifier constexpr
132
133 @groupheader{Header file}
134 @code
135 #include <kumi/algorithm/push_pop.hpp>
136 @endcode
137
138 @groupheader{Call Signature}
139
140 @code
141 template<product_type T>
142 constexpr auto pop_front(T && t);
143 @endcode
144
145 @subgroupheader{Parameters}
146
147 - `t`: Base product type
148
149 @subgroupheader{Return value}
150
151 - A product type composed of all elements of `t` except its first. Has no effect on empty product types.
152
153 @groupheader{Helper type}
154
155 @snippet include/kumi/algorithm/push_pop.hpp pop_front_t
156
157 Computes the return type of a call to kumi::pop_front
158
159 @groupheader{Examples}
160
161 @tab_begin
162
163 @tab{Tuple}
164 @godbolt{doc/tuple/algo/pop_front.cpp}
165
166 @tab{Record}
167 @godbolt{doc/record/algo/pop_front.cpp}
168
169 @tab_end
170 **/
171 //====================================================================================================================
172 KUMI_VARIABLE_ABI constexpr pop_front_t pop_front{};
173
174 //====================================================================================================================
175 /**
176 @ingroup kumi_generators
177
178 @var push_back
179 @brief Callable object constructing a product type by adding a value `v` at the end of `t`.
180
181 On record types, this function operates on elements as if they were ordered. The considered order is the order
182 of declaration.
183
184 @qualifier nodiscard
185 @qualifier inline
186 @qualifier constexpr
187
188 @groupheader{Header file}
189 @code
190 #include <kumi/algorithm/push_pop.hpp>
191 @endcode
192
193 @groupheader{Call Signature}
194
195 @code
196 template<product_type T, typename V>
197 constexpr auto push_back(T && t, V && v);
198 @endcode
199
200 @subgroupheader{Parameters}
201
202 - `t`: Base product type
203 - `v`: Value to insert at the end of `t`
204
205 @subgroupheader{Return value}
206
207 - A product type composed of all elements of `t` in order followed by `v`.
208
209 @groupheader{Helper type}
210
211 @snippet include/kumi/algorithm/push_pop.hpp push_back_t
212
213 Computes the return type of a call to kumi::push_back
214
215 @groupheader{Examples}
216
217 @tab_begin
218
219 @tab{Tuple}
220 @godbolt{doc/tuple/algo/push_back.cpp}
221
222 @tab{Record}
223 @godbolt{doc/record/algo/push_back.cpp}
224
225 @tab_end
226 **/
227 //====================================================================================================================
228 KUMI_VARIABLE_ABI constexpr push_back_t push_back{};
229
230 //====================================================================================================================
231 /**
232 @ingroup kumi_generators
233
234 @var pop_back
235 @brief Callable object removing the last (if any) element of `t`.
236
237 On record types, this function operates on elements as if they were ordered. The considered order is the order
238 of declaration.
239
240 @qualifier nodiscard
241 @qualifier inline
242 @qualifier constexpr
243
244 @groupheader{Header file}
245 @code
246 #include <kumi/algorithm/push_pop.hpp>
247 @endcode
248
249 @groupheader{Call Signature}
250
251 @code
252 template<product_type T>
253 constexpr auto pop_back(T && t);
254 @endcode
255
256 @subgroupheader{Parameters}
257
258 - `t`: Base product type
259
260 @subgroupheader{Return value}
261
262 - A product type composed of all elements of `t` except its last. Has no effect on empty product types.
263
264 @groupheader{Helper type}
265
266 @snippet include/kumi/algorithm/push_pop.hpp pop_back_t
267
268 Computes the return type of a call to kumi::pop_back
269
270 @groupheader{Examples}
271
272 @tab_begin
273
274 @tab{Tuple}
275 @godbolt{doc/tuple/algo/pop_back.cpp}
276
277 @tab{Record}
278 @godbolt{doc/record/algo/pop_back.cpp}
279
280 @tab_end
281 **/
282 //====================================================================================================================
283 KUMI_VARIABLE_ABI constexpr pop_back_t pop_back{};
284
285 namespace result
286 {
287 //! [push_front_t]
288 template<kumi::concepts::product_type T, typename V>
289 using push_front_t = decltype(kumi::push_front(std::declval<T>(), std::declval<V>()));
290
291 template<kumi::concepts::product_type T, typename V> struct push_front
292 {
293 using type = kumi::result::push_front_t<T, V>;
294 };
295
296 //! [push_front_t]
297
298 //! [pop_front_t]
299 template<kumi::concepts::product_type T> using pop_front_t = decltype(kumi::pop_front(std::declval<T>()));
300
301 template<kumi::concepts::product_type T> struct pop_front
302 {
303 using type = kumi::result::pop_front_t<T>;
304 };
305
306 //! [pop_front_t]
307
308 //! [push_back_t]
309 template<kumi::concepts::product_type T, typename V>
310 using push_back_t = decltype(kumi::push_back(std::declval<T>(), std::declval<V>()));
311
312 template<kumi::concepts::product_type T, typename V> struct push_back
313 {
314 using type = kumi::result::push_back_t<T, V>;
315 };
316
317 //! [push_back_t]
318
319 //! [pop_back_t]
320 template<kumi::concepts::product_type T> using pop_back_t = decltype(kumi::pop_back(std::declval<T>()));
321
322 template<kumi::concepts::product_type T> struct pop_back
323 {
324 using type = kumi::result::pop_back_t<T>;
325 };
326
327 //! [pop_back_t]
328 }
329 }
330