KUMI v5.0.0
Gorgeous Garnet
Loading...
Searching...
No Matches
Nomenclature

The library distinguishes the types of a product type as stored, its types as accessed, and the metadata that designate its components, under five names:

Notion Formal analogy Domain Example
Element Component type \( T_i \) Stored type float
Member Type of a projection Access float const&
Identifier Key Metadata "my_data"_id
Field Pair \( (I, S) \) Schema "velocity"_id = 1.f
Label Name Keys, diagnostics "velocity" as kumi::str

Element

An element is the type that a product type holds at a given position, the type \( T_i \) of the product \( T_1 \times \dots \times T_n \). The trait kumi::element_t gives it as declared, std::tuple_element_t<I, std::remove_cvref_t<T>>, with its qualifiers and references kept, so that the elements of kumi::tuple<int&, int const> are int& and int const.

On a record, the element at an index is the type of the field, and kumi::stored_element_t gives the type of the value that the field holds, float for a record built from "x"_id = 1.f:

#include <kumi/kumi.hpp>
#include <iostream>
#include <type_traits>
void show(char const* text, bool b)
{
std::cout << text << ": " << std::boolalpha << b << '\n';
}
int main()
{
using namespace kumi::literals;
using std::is_same_v;
using r_t = decltype(kumi::record{"x"_id = 1.f});
// the elements keep their reference and their const
show("tuple element 0 is int&", is_same_v<kumi::element_t<0, t_t>, int&>);
show("tuple element 1 is int const",
is_same_v<kumi::element_t<1, t_t>, int const>);
// a record stores its values in fields
show("record stores a float",
is_same_v<kumi::stored_element_t<0, r_t>, float>);
}
std::tuple_element_t< I, std::remove_cvref_t< T > > element_t
Provides indexed access to the types of the elements of a kumi::product_type.
Definition traits.hpp:145
decltype(kumi_implementation_defined) stored_element_t
Provides indexed access to the types of the elements of a product type and unwraps the returned field...
Definition traits.hpp:518
Fixed-size collection of heterogeneous fields with distinct labels.
Definition record.hpp:36
Fixed-size collection of heterogeneous values.
Definition tuple.hpp:35

Member

A member is the type of the result of a projection, the type of get<I>(t), which the trait kumi::member_t gives as decltype(get<I>(std::declval<T&&>())).

On kumi::tuple, it is the element with the value category and the const of the product type applied by reference collapsing: given kumi::tuple<int> t, get<0>(t) has the type int&, get<0>(std::move(t)) the type int&&, and get<0> of a kumi::tuple<int> const the type int const&, whereas on a kumi::tuple<int&> the first two have the type int&.

On an adapted type whose get returns by value, the member is that value type. On a record, the member at an index is a reference to the field, and kumi::stored_member_t gives the reference to the value that the field holds:

#include <kumi/kumi.hpp>
#include <iostream>
#include <type_traits>
void show(char const* text, bool b)
{
std::cout << text << ": " << std::boolalpha << b << '\n';
}
int main()
{
using std::is_same_v;
using t_t = kumi::tuple<int>;
using r_t = kumi::tuple<int&>;
// the value category and the const of the tuple reach the member
show("lvalue tuple<int> gives int&",
is_same_v<kumi::member_t<0, t_t&>, int&>);
show("rvalue tuple<int> gives int&&",
is_same_v<kumi::member_t<0, t_t&&>, int&&>);
show("const tuple<int> gives int const&",
is_same_v<kumi::member_t<0, t_t const&>, int const&>);
// except through a reference element
show("rvalue tuple<int&> gives int&",
is_same_v<kumi::member_t<0, r_t&&>, int&>);
}
decltype(get< I >(kumi::declval< T && >())) member_t
Computes the return type of a call to kumi::get.
Definition traits.hpp:169

Identifier

An identifier is a type that designates a field of a product type independently of its position and of its offset in memory. The value "x"_id, for instance, has the identifier type kumi::name<"x">. The concept kumi::concepts::identifier requires a nested type, and kumi::concepts::index, which describes the integral constants that designate a component by its position, requires a member value, so that a type with both, such as std::integral_constant, models both concepts. kumi::concepts::projection accepts either:

#include <kumi/kumi.hpp>
#include <iostream>
#include <type_traits>
void show(char const* text, bool b)
{
std::cout << text << ": " << std::boolalpha << b << '\n';
}
int main()
{
using namespace kumi::literals;
using n_t = kumi::name<"x">;
using i_t = std::integral_constant<std::size_t, 0>;
// "x"_id is a value of the identifier type kumi::name<"x">
show("\"x\"_id is a kumi::name<\"x\">",
std::is_same_v<decltype("x"_id), n_t>);
show("kumi::name is an identifier", kumi::concepts::identifier<n_t>);
show("kumi::name is an index", kumi::concepts::index<n_t>);
// an integral constant models both concepts
show("integral_constant is an identifier",
show("integral_constant is an index", kumi::concepts::index<i_t>);
}
Concept specifying a type represents an identifier.
Definition concepts.hpp:204
index concept
Definition concepts.hpp:173
Compile-time text based identifier.
Definition identifier.hpp:165

Field

A field binds an identifier to a value: kumi::field holds a value of a type T under an identifier Id, and the expression "x"_id = 42 builds one, which prints as its label and its value.

Its type is the ordered pair \( (I, S) \) of an identifier \( I \) and the type \( S \) of the value that it stores, given by kumi::stored_element_t, which is also the record type \( \{I : S\} \) of a single field. The fields of a kumi::record, or of a kumi::tuple that holds fields, define its schema:

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
using namespace kumi::literals;
// binding the identifier "x"_id to the value 42 builds a kumi::field
auto f = ("x"_id = 42);
std::cout << f << '\n';
std::cout << f.value << '\n';
}

Label

A label is the name of an identifier as a string known at compile time, of type kumi::str, which the function label() of a field returns. The library uses a label as a key, in the projection get<"x"> of a record and in the subscript of a record by a label that the literal _l builds, and in its diagnostics.

A const char* cannot point to a string literal as a template argument, and std::string_view is not a structural type, which is why the structural class kumi::str, of fixed size, holds a label:

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
using namespace kumi::literals;
kumi::record r = {"x"_id = 42, "y"_id = 13.37f};
// a label, a kumi::str, reads a field of a record by name
std::cout << kumi::get<"x">(r) << '\n';
std::cout << r["y"_l] << '\n';
// label() of a field type returns its label
using velocity = decltype("velocity"_id = 1.f);
std::cout << velocity::label() << '\n';
}
decltype(auto) constexpr get(array< T, N > &t) noexcept
Extracts the Ith element from a kumi::array.
Definition array.hpp:672
Previous
C++ Vocabulary