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

◆ extract()

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

Extracts a sub product type from a product type.

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 and I1 do not verify that 0 <= I0 <= I1 <= size_v<T>.
Parameters
tProduct Type to extract from
i0Compile-time index of the first element to extract.
i1Compile-time index past the last element to extract. By default, i1 is equal to size_v<T>.
Returns
A new product type containing the selected elements of t.

Helper type

namespace kumi::result
{
template<product_type T, std::size_t I0, std::size_t I1=-1> struct extract;
template<product_type T, std::size_t I0, std::size_t I1=-1>
using extract_t = typename extract<T,I0,I1>::type;
}
constexpr auto extract(T &&t, index_t< I0 > i0, index_t< I1 > i1) noexcept
Extracts a sub product type from a product type.
Definition extract.hpp:50

Computes the type returned by a call to extract.

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 head = extract(a,0_c,1_c);
auto mid = extract(a,1_c,3_c);
auto last = extract(a,kumi::index<3>);
std::cout << a << " => " << head << ' ' << mid << ' ' << last << '\n';
}
constexpr index_t< N > const index
Inline integral constant value for kumi::index_t.
Definition ct_helpers.hpp:76
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 head = extract(a,0_c,1_c);
auto mid = extract(a,1_c,3_c);
auto last = extract(a,kumi::index<3>);
std::cout << a << " => " << head << ' ' << mid << ' ' << last << '\n';
}
Fixed-size collection of heterogeneous tagged fields, tags are unique.
Definition record.hpp:36