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

◆ partition

template<template< typename > typename Pred>
partition_t<Pred> kumi::partition {}
inlineconstexprnodiscardnoexcept

Callable object partitionning a product type over a predicate.

On a record type, Pred is applied directly to the underlying elements of the fields.

Header file

#include <kumi/algorithm/partition.hpp>

Call Signature

template<product_type T>
constexpr auto partition<Pred>(T && t) noexcept;
constexpr partition_t< Pred > partition
Callable object partitionning a product type over a predicate.
Definition partition.hpp:115

Template Parameters

  • Pred: Compile-time predicate

Parameters

  • t: Product Type to process

Return value

  • A tuple containing the product type of all values which types satisfies Pred in t and the product type of all values which types does not satisfy Pred.

Helper type

template<template<typename> typename Pred, kumi::concepts::product_type T> struct partition
{
using type = decltype(kumi::partition<Pred>(std::declval<T>()));
};
template<template<typename> typename Pred, kumi::concepts::product_type T>
using partition_t = typename kumi::result::partition<Pred, T>::type;

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

Examples

Tuple

#include <kumi/kumi.hpp>
#include <type_traits>
#include <iostream>
int main()
{
int a = 4;
double b = 3.1415;
float c = 0.01f;
auto original = kumi::tuple{a,&a,b,&b,c,&c,'z',nullptr};
std::cout << original << "\n";
std::cout << "Pointers first: " << kumi::partition<std::is_pointer>(original) << "\n";
std::cout << "Real first: " << kumi::partition<std::is_floating_point>(original) << "\n";
std::cout << "nullptr first: " << kumi::partition<std::is_null_pointer>(original) << "\n";
}
Fixed-size collection of heterogeneous values.
Definition tuple.hpp:33

Record

#include <kumi/kumi.hpp>
#include <type_traits>
#include <iostream>
int main()
{
using namespace kumi::literals;
int a = 4;
double b = 3.1415;
float c = 0.01f;
auto original = kumi::record{"a"_id = a,"b"_id = &a,"c"_id = b,"d"_id = &b,"e"_id = c,"f"_id = &c,"g"_id = 'z',"h"_id = nullptr};
std::cout << original << "\n";
std::cout << "Pointers first: " << kumi::partition<std::is_pointer>(original) << "\n";
std::cout << "Real first: " << kumi::partition<std::is_floating_point>(original) << "\n";
std::cout << "nullptr first: " << kumi::partition<std::is_null_pointer>(original) << "\n";
}
Fixed-size collection of heterogeneous tagged fields, tags are unique.
Definition record.hpp:36