GCC Code Coverage Report


Directory: include/kumi/
File: include/kumi/algorithm/extract.hpp
Date: 2026-10-14 16:33:56
Exec Total Coverage
Lines: 7 7 100.0%
Functions: 0 0 -%
Branches: 0 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 struct extract_t
13 {
14 template<kumi::concepts::product_type T, std::size_t B, std::size_t E, std::size_t S>
15 [[nodiscard]] KUMI_ABI constexpr auto operator()(T&& t,
16 kumi::index_t<B>,
17 kumi::index_t<E>,
18 kumi::index_t<S>) const noexcept
19 {
20 static_assert((B <= kumi::size_v<T>) && (E <= kumi::size_v<T>), "[KUMI] - Invalid index");
21 12 return kumi::_::builder(KUMI_FWD(t), kumi::function::slice_index_sequence<B, E, S>{});
22 }
23
24 template<kumi::concepts::product_type T, std::size_t B, std::size_t E>
25 [[nodiscard]] KUMI_ABI constexpr auto operator()(T&& t, kumi::index_t<B>, kumi::index_t<E>) const noexcept
26 {
27 static_assert((B <= kumi::size_v<T>) && (E <= kumi::size_v<T>), "[KUMI] - Invalid index");
28 85 return kumi::_::builder(KUMI_FWD(t), kumi::function::slice_index_sequence<B, E>{});
29 }
30
31 template<kumi::concepts::product_type T, std::size_t B>
32 [[nodiscard]] KUMI_ABI constexpr auto operator()(T&& t, kumi::index_t<B> b) const noexcept
33 {
34 static_assert(B <= kumi::size_v<T>, "[KUMI] - Invalid index");
35 23 return (*this)(KUMI_FWD(t), b, kumi::index<size_v<T>>);
36 }
37 };
38
39 struct remove_t
40 {
41 template<kumi::concepts::product_type T, std::size_t B, std::size_t E, std::size_t S>
42 [[nodiscard]] KUMI_ABI constexpr auto operator()(T&& t,
43 kumi::index_t<B>,
44 kumi::index_t<E>,
45 kumi::index_t<S>) const noexcept
46 {
47 static_assert((B <= kumi::size_v<T>) && (E <= kumi::size_v<T>), "[KUMI] - Invalid index");
48 using kept = kumi::function::remove_index_sequence<kumi::size_v<T>, B, E, S>;
49 108 return kumi::_::builder(KUMI_FWD(t), kept{});
50 }
51
52 template<kumi::concepts::product_type T, std::size_t B, std::size_t E>
53 [[nodiscard]] KUMI_ABI constexpr auto operator()(T&& t, kumi::index_t<B> b, kumi::index_t<E> e) const noexcept
54 {
55 static_assert((B <= kumi::size_v<T>) && (E <= kumi::size_v<T>), "[KUMI] - Invalid index");
56 88 return (*this)(KUMI_FWD(t), b, e, kumi::index<1>);
57 }
58
59 template<kumi::concepts::product_type T, std::size_t B>
60 [[nodiscard]] KUMI_ABI constexpr auto operator()(T&& t, kumi::index_t<B> b) const noexcept
61 {
62 static_assert(B <= kumi::size_v<T>, "[KUMI] - Invalid index");
63 24 return (*this)(KUMI_FWD(t), b, kumi::index<kumi::size_v<T>>);
64 }
65 };
66
67 struct split_t
68 {
69 template<kumi::concepts::product_type T, std::size_t I>
70 [[nodiscard]] KUMI_ABI constexpr auto operator()(T&& t, kumi::index_t<I>) const noexcept
71 {
72 static_assert(I <= kumi::size_v<T>, "[KUMI] - Invalid index");
73
74 using first = std::make_index_sequence<I>;
75 using last = kumi::function::shift_index_sequence<I, kumi::size_v<T> - I>;
76 21 return kumi::tuple{kumi::_::builder(KUMI_FWD(t), first{}), kumi::_::builder(KUMI_FWD(t), last{})};
77 }
78 };
79
80 //====================================================================================================================
81 /**
82 @ingroup kumi_generators
83
84 @var extract
85 @brief Callable object extracting a sub product type from a product type
86
87 On record types, this function operates on elements as if they were ordered. The considered order is the order
88 of declaration.
89
90 @note This function will issue a compile time error if `I0` and `I1` do not verify that
91 `0 <= I0 <= I1 <= size_v<T>`.
92
93 @qualifier nodiscard
94 @qualifier inline
95 @qualifier constexpr
96 @qualifier noexcept
97
98 @groupheader{Header file}
99 @code
100 #include <kumi/algorithm/extract.hpp>
101 @endcode
102
103 @groupheader{Call Signature}
104
105 @code
106 template<product_type T, std::size_t I0, std::size_t I1>
107 constexpr auto extract(T && t, kumi::index_t<I0>, kumi::index_t<I1>) noexcept; // 1
108 @endcode
109
110 @code
111 template<product_type T, std::size_t I0>
112 constexpr auto extract(T && t, kumi::index_t<I0>) noexcept; // 2
113 @endcode
114
115 @subgroupheader{Parameters}
116
117 - `t`: Product Type to extract elements from
118 - `i0`: Compile-time index of the first element to extract
119 - `i1`: Compile-time index past the last element to extract
120
121 @subgroupheader{Return value}
122
123 - 1. A new product type containing the selected range of elements of `t`.
124 - 2. A new product type containing the selected elements of `t` using `size_v<T>` as the last index.
125
126 @groupheader{Helper type}
127
128 @snippet include/kumi/algorithm/extract.hpp extract_t
129
130 Computes the return type of a call to kumi::extract
131
132 @groupheader{Examples}
133
134 @tab_begin
135
136 @tab{Tuple}
137 @godbolt{doc/tuple/algo/extract.cpp}
138
139 @tab{Record}
140 @godbolt{doc/record/algo/extract.cpp}
141
142 @tab_end
143 **/
144 //====================================================================================================================
145 KUMI_VARIABLE_ABI constexpr extract_t extract{};
146
147 //====================================================================================================================
148 /**
149 @ingroup kumi_generators
150
151 @var remove
152 @brief Callable object removing a sub product type from a product type
153
154 On record types, this function operates on elements as if they were ordered. The considered order is the order
155 of declaration.
156
157 @note This function will issue a compile time error if `I0` and `I1` do not verify that
158 `0 <= I0 <= I1 <= size_v<T>`.
159
160 @qualifier nodiscard
161 @qualifier inline
162 @qualifier constexpr
163 @qualifier noexcept
164
165 @groupheader{Header file}
166 @code
167 #include <kumi/algorithm/extract.hpp>
168 @endcode
169
170 @groupheader{Call Signature}
171
172 @code
173 template<product_type T, std::size_t I0, std::size_t I1>
174 constexpr auto remove(T && t, kumi::index_t<I0>, kumi::index_t<I1>) noexcept; // 1
175 @endcode
176
177 @code
178 template<product_type T, std::size_t I0>
179 constexpr auto remove(T && t, kumi::index_t<I0>) noexcept; // 2
180 @endcode
181
182 @subgroupheader{Parameters}
183
184 - `t`: Product Type to remove elements from
185 - `i0`: Compile-time index of the first element to extract
186 - `i1`: Compile-time index past the last element to extract
187
188 @subgroupheader{Return value}
189
190 - 1. A new product type containing the elements of t without the range of elements from I0 to I1.
191 - 2. A new product type containing the elements of t without the range of elements from I0 to `size_v<T>`.
192
193 @groupheader{Helper type}
194
195 @snippet include/kumi/algorithm/extract.hpp remove_t
196
197 Computes the return type of a call to kumi::remove
198
199 @groupheader{Examples}
200
201 @tab_begin
202
203 @tab{Tuple}
204 @godbolt{doc/tuple/algo/remove.cpp}
205
206 @tab{Record}
207 @godbolt{doc/record/algo/remove.cpp}
208
209 @tab_end
210 **/
211 //====================================================================================================================
212 KUMI_VARIABLE_ABI constexpr remove_t remove{};
213
214 //====================================================================================================================
215 /**
216 @ingroup kumi_generators
217
218 @var split
219 @brief Callable object splitting a product type into two
220
221 Split a product type in two product_type containing all the elements before and after a given index.
222 On record types, this function operates on elements as if they were ordered. The considered order is the order
223 of declaration.
224
225 @note This function will issue a compile time error if `I0` is not in `[0, size_v<T>[`.
226
227 @qualifier nodiscard
228 @qualifier inline
229 @qualifier constexpr
230 @qualifier noexcept
231
232 @groupheader{Header file}
233 @code
234 #include <kumi/algorithm/extract.hpp>
235 @endcode
236
237 @groupheader{Call Signature}
238
239 @code
240 template<product_type T, std::size_t I0>
241 constexpr auto split(T && t, kumi::index_t<I0>) noexcept;
242 @endcode
243
244 @subgroupheader{Parameters}
245
246 - `t`: Product Type to extract elements from
247 - `i0`: Compile-time index of the split pivot
248
249 @subgroupheader{Return value}
250
251 - A new tuple containing the two sub parts of `t` cut at `i0`
252
253 @groupheader{Helper type}
254
255 @snippet include/kumi/algorithm/extract.hpp split_t
256
257 Computes the return type of a call to kumi::split
258
259 @groupheader{Examples}
260
261 @tab_begin
262
263 @tab{Tuple}
264 @godbolt{doc/tuple/algo/split.cpp}
265
266 @tab{Record}
267 @godbolt{doc/record/algo/split.cpp}
268
269 @tab_end
270 **/
271 //====================================================================================================================
272 KUMI_VARIABLE_ABI constexpr split_t split{};
273
274 namespace result
275 {
276 //! [extract_t]
277 template<kumi::concepts::product_type T, std::size_t... I>
278 requires((sizeof...(I) == 1) || (sizeof...(I) == 2))
279 using extract_t = decltype(kumi::extract(std::declval<T>(), kumi::index_t<I>{}...));
280
281 template<kumi::concepts::product_type T, std::size_t... I>
282 requires((sizeof...(I) == 1) || (sizeof...(I) == 2))
283 struct extract
284 {
285 using type = kumi::result::extract_t<T, I...>;
286 };
287
288 //! [extract_t]
289
290 //! [remove_t]
291 template<kumi::concepts::product_type T, std::size_t... I>
292 requires((sizeof...(I) == 1) || (sizeof...(I) == 2))
293 using remove_t = decltype(kumi::remove(std::declval<T>(), kumi::index_t<I>{}...));
294
295 template<kumi::concepts::product_type T, std::size_t... I>
296 requires((sizeof...(I) == 1) || (sizeof...(I) == 2))
297 struct remove
298 {
299 using type = kumi::result::remove_t<T, I...>;
300 };
301
302 //! [remove_t]
303
304 //! [split_t]
305 template<kumi::concepts::product_type T, std::size_t I>
306 using split_t = decltype(kumi::split(std::declval<T>(), kumi::index_t<I>{}));
307
308 template<kumi::concepts::product_type T, std::size_t I> struct split
309 {
310 using type = kumi::result::split_t<T, I>;
311 };
312
313 //! [split_t]
314 }
315 }
316