KUMI v5.0.0
Gorgeous Garnet
Loading...
Searching...
No Matches
Utility Types and Functions

Types and functions to adapt, build, name, index, and introspect product types. More...

Topics

 kumi::capture_field
 Creates a field from a given value keeping the qualifiers.
 kumi::field_cast
 Casts the provided value to the target type using static_cast.
 kumi::field_value_of
 Extracts the value from a kumi::concepts::field or returns the parameter.
 kumi::get_index_of_field
 Helper to retrieve the index of a type in a product type by its identifier.
 kumi::get_index_of_label
 Helper to retrieve the index of a type in a product type by its identifier.
 kumi::get_index_of_type
 Helper to retrieve the index of a type in a product type by its type.
 kumi::identifier_of
 Extracts the identifier of a kumi::concepts::field, or returns kumi::unknown.
 kumi::identifiers
 Creates a kumi::projection_map object, deducing the target type from the types of arguments.
 kumi::index
 Inline integral constant value for kumi::index_t.
 kumi::indexes
 Creates a kumi::projection_map object, deducing the target type from the types of arguments.
 kumi::label
 Inline literal constant value for kumi::label_t.
 kumi::label_of
 Extracts the label of a kumi::concepts::field, or returns the value of kumi::unknown.
 kumi::make_indexes
 Creates a kumi::projection_map object, deducing the target type from the types of arguments.
 kumi::members_of
 Extracts the identifiers of the fields of a kumi::product_type.
 kumi::none
 Inline constant representing a kumi::unit.
 kumi::only
 Option restricting an identifier to accept a single type T.
 kumi::projection_map
 kumi::projection_map deduction guide
 kumi::values_of
 Extracts the values of the fields of a kumi::product_type.

Classes

class  kumi::as< T >
 Lightweight type-wrapper. More...
class  kumi::builder< T >
 kumi::builder provides a generic way of defining a product type. More...
class  kumi::field< Id, T >
 Named wrapper over a type. More...
class  kumi::identifier< ID, Checker >
 identifier definition class More...
class  kumi::index_t< N >
 Integral constant type. More...
class  kumi::label_t< Label >
 Literal constant type. More...
class  kumi::name< ID >
 Compile-time text based identifier. More...
class  kumi::projection_map< V >
 A stateless, compile-time schema for product type transformation. More...
class  kumi::str< N >
 Static string used to create named fields. More...
class  kumi::unit
 A type representing the product of no type, also called the unit type. More...
class  kumi::unknown
 Type indicating an identifier was not found in a given kumi::product_type. More...

Functions

auto as_streamable (auto e)
 Provides an extension point as_streamable in order to output types with no stream operator defined.
template<char... c>
constexpr auto kumi::operator""_c () noexcept
 Forms a integral constant literal of the desired value.
template<kumi::str ID>
constexpr auto kumi::operator""_id () noexcept
 Forms a constant string literal of the desired value.
template<kumi::str ID>
constexpr auto kumi::operator""_l () noexcept
 Forms a constant string literal of the desired value.
template<template< class > class Pred>
constexpr auto kumi::predicate () noexcept
 Convert a unary template meta-program in a running predicate.
kumi::str constexpr to_str (auto e)
 Provides an extension point to_str in order to output types with no textual representation defined.

Friends

template<typename CharT, typename Traits>
std::basic_ostream< CharT, Traits > & operator<< (std::basic_ostream< CharT, Traits > &os, field const &w) noexcept
 Inserts a kumi::field in an output stream.
template<typename CharT, typename Traits>
std::basic_ostream< CharT, Traits > & operator<< (std::basic_ostream< CharT, Traits > &os, field const &w) noexcept
 Inserts a kumi::field in an output stream.

Variables

template<typename T, typename...>
kumi::declfn_t< T && > kumi::declval
 Converts a type T to an rvalue reference type for use in unevaluated contexts.
template<template< class > typename Traits>
constexpr traits_check< Traits > kumi::if_ = {}
 Option restricting an identifier to accept values whose type satisfies the trait Traits.

Detailed Description

Types and functions to adapt, build, name, index, and introspect product types.

Function Documentation

◆ as_streamable()

auto as_streamable ( auto e)

Provides an extension point as_streamable in order to output types with no stream operator defined.

This function does not exist in the kumi namespace, it is supposed to be found via Argument Dependant Lookup for user defined types.

Parameters
eThe value of the element to output.
Returns
A value that can be passed to an output stream.

Example:

#include <kumi/kumi.hpp>
#include <iostream>
#include <string>
#include <cstdint>
namespace ns
{
struct price
{
std::uint64_t integer;
std::uint64_t decimal;
};
auto as_streamable(price const& p)
{
return std::to_string(p.integer) + "."
+ std::to_string(p.decimal);
}
}
int main()
{
ns::price baguette{1, 50};
ns::price cards {7, 90};
kumi::tuple shop_list = {baguette, cards};
std::cout << shop_list << "\n";
}
auto as_streamable(auto e)
Provides an extension point as_streamable in order to output types with no stream operator defined.
Fixed-size collection of heterogeneous values.
Definition tuple.hpp:35

◆ operator""_c()

template<char... c>
auto kumi::literals::operator""_c ( )
constexprnoexcept

Forms a integral constant literal of the desired value.

Returns
An instance of kumi::index_t for the specified integral value

Example:

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
using namespace kumi::literals;
auto v = 42_c;
auto w = kumi::index<63>;
std::cout << v << "\n";
std::cout << w << "\n";
}

◆ operator""_id()

template<kumi::str ID>
auto kumi::literals::operator""_id ( )
constexprnoexcept

Forms a constant string literal of the desired value.

Returns
An instance of kumi::name for the specified string

Example:

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
using namespace kumi::literals;
auto n = "Peter"_id;
auto s = kumi::name<"Jackson">{};
std::cout << n << "\n";
std::cout << s << "\n";
}
Compile-time text based identifier.
Definition identifier.hpp:165

◆ operator""_l()

template<kumi::str ID>
auto kumi::literals::operator""_l ( )
constexprnoexcept

Forms a constant string literal of the desired value.

Returns
An instance of kumi::label for the specified string
Note
It differs from the ""_id operator on the type and the overload that it will pick up. An identifier and a label are two different parts of a field. Label represents the value that is displayed.

Example:

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
using namespace kumi::literals;
auto n = "Peter"_l;
auto s = kumi::label<"Jackson">;
std::cout << n << "\n";
std::cout << s << "\n";
}

◆ predicate()

template<template< class > class Pred>
auto kumi::predicate ( )
nodiscardconstexprnoexcept

Convert a unary template meta-program in a running predicate.

Template Parameters
PredUnary template meta-program to convert.
Returns
A Callable Object applying Pred to the type of its arguments

◆ to_str()

kumi::str constexpr to_str ( auto e)
constexpr

Provides an extension point to_str in order to output types with no textual representation defined.

This function does not exist in the kumi namespace, it is supposed to be found via Argument Dependant Lookup for user defined types. It is used in order to handle identifiers/fields display and manipulations. to_str needs to be constexpr callable, if not some concepts might fail unexpectedly.

Parameters
eThe value of the element to output.
Returns
A kumi::str representing the input type

Example:

#include <kumi/kumi.hpp>
#include <iostream>
#include <string>
#include <cstdint>
namespace ns
{
struct tax_t : kumi::identifier<tax_t>
{
using kumi::identifier<tax_t>::operator=;
friend constexpr auto to_str(tax_t const&)
{
return kumi::str{"Taxes Threshold"};
}
};
inline constexpr tax_t tax{};
struct deduction_t : kumi::identifier<deduction_t>
{
using kumi::identifier<deduction_t>::operator=;
};
inline constexpr deduction_t deduction{};
}
int main()
{
kumi::record payment= {ns::tax = 12.80, ns::deduction = 10.8};
std::cout << payment << "\n";
}
kumi::str constexpr to_str(auto e)
Provides an extension point to_str in order to output types with no textual representation defined.
identifier definition class
Definition identifier.hpp:89
Fixed-size collection of heterogeneous fields with distinct labels.
Definition record.hpp:36
Static string used to create named fields.
Definition str.hpp:31

Variable Documentation

◆ declval

template<typename T, typename...>
kumi::declfn_t<T&&> kumi::declval
extern

Converts a type T to an rvalue reference type for use in unevaluated contexts.

Call Signature

template<class T>
constexpr std::add_rvalue_reference_t<T> declval() noexcept;
kumi::declfn_t< T && > declval
Converts a type T to an rvalue reference type for use in unevaluated contexts.

Examples

#include <kumi/kumi.hpp>
struct Foo { int bar(); };
// Determine the return type without constructing Foo
using bar_type = decltype(kumi::declval<Foo>().bar()); // bar_type is int
Note
The function has no defined body because it is only used in unevaluated contexts. Attempting to call it results in a linker error

◆ if_

template<template< class > typename Traits>
traits_check<Traits> kumi::if_ = {}
inlineconstexpr

Option restricting an identifier to accept values whose type satisfies the trait Traits.

Template Parameters
TraitsTraits that the parametrized identifier will use to validate its value.
#include <kumi/kumi.hpp>
#include <iostream>
using namespace kumi::literals;
template<typename T>
struct is_big : std::bool_constant<(sizeof(T) > 2)> {};
inline constexpr auto large_value = kumi::identifier("large"_id, kumi::if_<is_big>);
int main()
{
std::cout << kumi::record{ large_value = 9.6 } << "\n";
}
constexpr traits_check< Traits > if_
Option restricting an identifier to accept values whose type satisfies the trait Traits.
Definition identifier.hpp:45