KUMI v3.1.0
Exquisite Epidote
Loading...
Searching...
No Matches

◆ split()

template<std::size_t I0, concepts::product_type T>
auto kumi::split ( T && t,
index_t< I0 > i0 )
inlinenodiscardconstexprnoexcept

Split a product type into two.

Split a product type in two product_type containing all the elements before and after a given index. On record types, this function operates on elements as if they were ordered. The considered order is the order of declaration.

Note
This function will issue a compile time error if I0 is not in [0, sizeof...(Ts)[.
Parameters
tProduct Type to split.
i0Compile-time index of the split pivot.
Returns
A new tuple containing the two sub parts of t cut at index I.

Helper type

namespace kumi::result
{
template<product_type T, std::size_t I0> struct split;
template<product_type T, std::size_t I0>
using split_t = typename split<T,I0>::type;
}
constexpr auto split(T &&t, index_t< I0 > i0) noexcept
Split a product type into two.
Definition extract.hpp:105

Computes the type returned by a call to split.

Examples:

Tuple:

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
using namespace kumi::literals;
kumi::tuple a = { 1, 2.3, 4.5f,'6',"7", short{89} };
auto[first, second] = split(a, 3_c);
std::cout << a << "\n";
std::cout << first << "\n";
std::cout << second << "\n";
}
Fixed-size collection of heterogeneous values.
Definition tuple.hpp:33

Record:

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
using namespace kumi::literals;
kumi::record a = { "a"_id = 1, "b"_id = 2.3, "c"_id = 4.5f,"d"_id = '6',
"e"_id = "7", "f"_id = short{89} };
auto[first, second] = split(a, 3_c);
std::cout << a << "\n";
std::cout << first << "\n";
std::cout << second << "\n";
}
Fixed-size collection of heterogeneous tagged fields, tags are unique.
Definition record.hpp:36