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

◆ flatten_all

flatten_all_t kumi::flatten_all {}
inlineconstexprnodiscard

Callable object converting recursively a product type of product types into a product type of all elements.

Recursively converts a product type of product types t into a product type of all elements of said product types.

If the Callable object f is provided, non-product type elements are processed by f before being inserted.

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 flattened. Thus a record inside a tuple will not be flattened.

Header file

#include <kumi/algorithm/flatten.hpp>

Call Signature

template<product_type T, typename Function>
constexpr auto flatten(T && t, Function && f) noexcept; // 1
constexpr flatten_t flatten
Callable object converting a product type of product types into a product type of all elements.
Definition flatten.hpp:249
template<product_type T>
constexpr auto flatten(T && t) noexcept; // 2

Parameters

  • t: Product type to process
  • f: Optional Callable object to apply when a sub-tuple is flattened

Return value

  • A product type composed of all elements of t flattened recursively

Helper type

template<kumi::concepts::product_type T, typename Func = void> struct flatten_all
{
using type = decltype(kumi::flatten_all(std::declval<T>(), std::declval<Func>()));
};
template<kumi::concepts::product_type T> struct flatten_all<T>
{
using type = decltype(kumi::flatten_all(std::declval<T>()));
};
template<kumi::concepts::product_type T, typename Func = void>
using flatten_all_t = typename kumi::result::flatten_all<T, Func>::type;

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

Examples

Tuple

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
auto nbrs = kumi::tuple{1,2ULL,3};
auto more_nbrs = kumi::tuple{short{0},nbrs,4.};
auto ltrs = kumi::tuple{'a','b','c'};
auto r = kumi::flatten_all( kumi::tuple{3.5,nbrs,'z',more_nbrs,5.35f,ltrs} );
std::cout << r << "\n";
auto sz = kumi::flatten_all ( kumi::tuple{3.5,nbrs,'z',more_nbrs,5.35f,ltrs}
, [](auto e) { return sizeof(e); }
);
std::cout << sz << "\n";
}
constexpr flatten_all_t flatten_all
Callable object converting recursively a product type of product types into a product type of all ele...
Definition flatten.hpp:313
Fixed-size collection of heterogeneous values.
Definition tuple.hpp:33

Record

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
using namespace kumi::literals;
auto nbrs = kumi::record{"f"_id = 1,"s"_id = 2ULL,"t"_id = 3};
auto more_nbrs = kumi::record{"z"_id = short{0},"n"_id = nbrs,"l"_id = 4.};
auto ltrs = kumi::record{"alpha"_id = 'a',"beta"_id = 'b', "gamma"_id = 'c'};
auto r = kumi::flatten_all( kumi::record{"a"_id = 3.5,"b"_id = nbrs,"c"_id = 'z'
,"d"_id = more_nbrs,"e"_id = 5.35f,"f"_id = ltrs} );
std::cout << r << "\n";
auto sz = kumi::flatten_all (kumi::record{"a"_id = 3.5,"b"_id = nbrs,"c"_id = 'z'
,"d"_id = more_nbrs,"e"_id = 5.35f,"f"_id = ltrs}
, [](auto e) { return sizeof(e); }
);
std::cout << sz << "\n";
}
Fixed-size collection of heterogeneous tagged fields, tags are unique.
Definition record.hpp:36