KUMI v4.0.0
Flawless Fluorite
Loading...
Searching...
No Matches

◆ compress

compress_t kumi::compress {}
inlineconstexprnodiscard

Callable object converting a product type of product type into a single product type recursively, or returns the input.

This construction naturally arises from the definition of product types, a product type of the form T(T(x...)) is strictly equivalent to T(x...) as long as the T is the same type.

On record types, the names of the outer record are concatenated to the inner ones ultimately constructing names such as "outer.inner". If the input is a product type containing record types or vice versa only the inner types matching the outer semantic will be compressed. Thus a record inside a tuple will not be compressed.

Header file

#include <kumi/algorithm/flatten.hpp>

Call Signature

template<product_type T>
constexpr auto compress(T && t) noexcept;
constexpr compress_t compress
Callable object converting a product type of product type into a single product type recursively,...
Definition flatten.hpp:197

Parameters

  • t: Product type to process

Return value

  • The resulting value of the application of T0(...(Tn(values))) => T(values)

Helper type

template<kumi::concepts::product_type T> struct compress
{
using type = decltype(kumi::compress(std::declval<T>()));
};
template<kumi::concepts::product_type T> using compress_t = typename kumi::result::compress<T>::type;

Computes the return type of a call to kumi::compress

Examples

Tuple

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
auto t = kumi::tuple{1,2,3};
auto nest_1 = kumi::tuple{t};
auto nest_2 = kumi::tuple{nest_1};
auto t2 = kumi::tuple{nest_1, nest_2};
std::cout << kumi::compress( nest_2 ) << "\n";
std::cout << kumi::compress( t2 ) << "\n";
}
Fixed-size collection of heterogeneous values.
Definition tuple.hpp:33

Record

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
using namespace kumi::literals;
auto r = kumi::record{"a"_id = 1,"b"_id = 2, "c"_id = 3};
auto nest_1 = kumi::record{"e"_id = r};
auto nest_2 = kumi::record{"f"_id = nest_1};
auto r2 = kumi::record{"g"_id = nest_1, "h"_id = nest_2};
std::cout << kumi::compress( nest_2 ) << "\n";
std::cout << kumi::compress( r2 ) << "\n";
}
Fixed-size collection of heterogeneous tagged fields, tags are unique.
Definition record.hpp:36