KUMI v3.1.0
Exquisite Epidote
Loading...
Searching...
No Matches

Fixed-size collection of heterogeneous tagged fields, tags are unique. More...

#include <kumi/product_types/record.hpp>

Detailed Description

template<typename... Ts>
class kumi::record< Ts >

Fixed-size collection of heterogeneous tagged fields, tags are unique.

kumi::record provides an aggregate based implementation of a record. It provides algorithms and functions designed to facilitate record's handling and transformations.

kumi::record is also compatible with standard tuple operations and structured bindings to some extent.

Template Parameters
TsSequence of fields stored inside kumi::record.
See also
Record Type \( (\{l_A: A\} \times \{l_B: B\}) \)

Example:

#include <iostream>
#include <stdexcept>
#include <string>
#include <kumi/kumi.hpp>
using namespace kumi::literals;
auto get_student(int id)
{
switch (id)
{
case 0: return kumi::record{"GPA"_id = 3.8, "grade"_id = 'A', "name"_id = std::string{"Lisa Simpson"}};
case 1: return kumi::record{"GPA"_id = 2.9, "grade"_id = 'C', "name"_id = std::string{"Milhouse Van Houten"}};
case 2: return kumi::record{"GPA"_id = 1.7, "grade"_id = 'D', "name"_id = std::string{"Ralph Wiggum"}};
case 3: return kumi::record{"GPA"_id = 0.6, "grade"_id = 'F', "name"_id = std::string{"Bart Simpson"}};
}
throw std::invalid_argument("id");
}
int main()
{
const auto student0 = get_student(0);
std::cout << "ID: 0, "
<< "GPA: " << kumi::get<"GPA">(student0) << ", "
<< "grade: " << kumi::get<"grade">(student0) << ", "
<< "name: " << kumi::get<"name">(student0) << '\n';
const auto student1 = get_student(1);
std::cout << "ID: 1, "
<< "GPA: " << kumi::get<double>(student1) << ", "
<< "grade: " << kumi::get<char>(student1) << ", "
<< "name: " << kumi::get<std::string>(student1) << '\n';
double gpa2;
char grade2;
std::string name2;
kumi::tie<"GPA"_id, "grade"_id, "name"_id>(gpa2, grade2, name2) = get_student(2);
std::cout << "ID: 2, "
<< "GPA: " << gpa2 << ", "
<< "grade: " << grade2 << ", "
<< "name: " << name2 << '\n';
// C++17 structured binding:
const auto [gpa3, grade3, name3] = get_student(3);
std::cout << "ID: 3, "
<< gpa3 << ", "
<< grade3 << ", "
<< name3 << '\n';
}
decltype(auto) constexpr get(record< Ts... > &r) noexcept
Extracts the Ith field from a kumi::record.
Definition record.hpp:604
Fixed-size collection of heterogeneous tagged fields, tags are unique.
Definition record.hpp:36

Public Member Functions

template<typename... Us>
requires (concepts::equivalent<record, record<Us...>>)
constexpr recordoperator= (record< Us... > &&other)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<typename... Us>
requires (concepts::equivalent<record, record<Us...>>)
constexpr recordoperator= (record< Us... > const &other)
 Replaces the content of the record with the content of another record.

(Note that these are not member symbols.)

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

Accessors

template<std::size_t I>
requires (I < sizeof...(Ts))
constexpr decltype(auto) operator[] (index_t< I > i) &noexcept
 Extracts the Ith field from a kumi::record.
template<std::size_t I>
requires (I < sizeof...(Ts))
constexpr decltype(auto) operator[] (index_t< I >) &&noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<std::size_t I>
requires (I < sizeof...(Ts))
constexpr decltype(auto) operator[] (index_t< I >) const &&noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<std::size_t I>
requires (I < sizeof...(Ts))
constexpr decltype(auto) operator[] (index_t< I >) const &noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<typename T>
requires (concepts::uniquely_typed<kumi_implementation_defined...> && concepts::contains_type<T, kumi_implementation_defined...>)
constexpr decltype(auto) operator[] (as< T > type) &noexcept
 Extracts the element with type T from a kumi::record.
template<typename T>
requires (concepts::uniquely_typed<kumi_implementation_defined...> && concepts::contains_type<T, kumi_implementation_defined...>)
constexpr decltype(auto) operator[] (as< T >) &&noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<typename T>
requires (concepts::uniquely_typed<kumi_implementation_defined...> && concepts::contains_type<T, kumi_implementation_defined...>)
constexpr decltype(auto) operator[] (as< T >) const &&noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<typename T>
requires (concepts::uniquely_typed<kumi_implementation_defined...> && concepts::contains_type<T, kumi_implementation_defined...>)
constexpr decltype(auto) operator[] (as< T >) const &noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<str Name>
requires (concepts::contains_label<label_t<Name>, Ts...>)
constexpr decltype(auto) operator[] (label_t< Name > l) &noexcept
 Extracts the element of the field labeled L from a kumi::record.
template<str Name>
requires (concepts::contains_label<label_t<Name>, Ts...>)
constexpr decltype(auto) operator[] (label_t< Name >) &&noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<str Name>
requires (concepts::contains_label<label_t<Name>, Ts...>)
constexpr decltype(auto) operator[] (label_t< Name >) const &&noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<str Name>
requires (concepts::contains_label<label_t<Name>, Ts...>)
constexpr decltype(auto) operator[] (label_t< Name >) const &noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<concepts::identifier Id>
requires (concepts::contains_field<Id, Ts...>)
constexpr decltype(auto) operator[] (Id const &) &noexcept
 Extracts the element whose identifier matches Id from a kumi::record.
template<concepts::identifier Id>
requires (concepts::contains_field<Id, Ts...>)
constexpr decltype(auto) operator[] (Id const &) &&noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<concepts::identifier Id>
requires (concepts::contains_field<Id, Ts...>)
constexpr decltype(auto) operator[] (Id const &) const &&noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<concepts::identifier Id>
requires (concepts::contains_field<Id, Ts...>)
constexpr decltype(auto) operator[] (Id const &) const &noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Properties

constexpr auto values () noexcept
 Returns references to the values of the element in a kumi::record.
constexpr auto values () const noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
static constexpr auto size () noexcept
static constexpr bool empty () noexcept
static constexpr auto identifiers () noexcept
 Returns the identifiers associated to the elements of a kumi::record.
static constexpr auto labels () noexcept
 Returns the labels associated to the elements of a kumi::record.

Comparison operators

template<typename... Us>
requires (concepts::named_equality_comparable<record, record<Us...>>)
constexpr auto operator== (record const &self, record< Us... > const &other) noexcept
 Compares a record with an other for equality.
template<typename... Us>
requires (concepts::named_equality_comparable<record, record<Us...>>)
constexpr auto operator!= (record const &self, record< Us... > const &other) noexcept
 Compares a record with an other for inequality.

Record Deduction Guides

template<typename... Ts>
KUMI_CUDA record (Ts &&...) -> record< std::unwrap_ref_decay_t< Ts >... >
 kumi::record deduction guide

Record accessors

template<std::size_t I, typename... Ts>
decltype(auto) constexpr get (record< Ts... > &r) noexcept
 Extracts the Ith field from a kumi::record.
template<std::size_t I, typename... Ts>
decltype(auto) constexpr get (record< Ts... > &&r) noexcept
template<std::size_t I, typename... Ts>
decltype(auto) constexpr get (record< Ts... > const &r) noexcept
template<std::size_t I, typename... Ts>
decltype(auto) constexpr get (record< Ts... > const &&r) noexcept
template<str L, typename... Ts>
decltype(auto) constexpr get (record< Ts... > &r) noexcept
 Extracts the element of the field labeled L from a kumi::record if it exists.
template<str L, typename... Ts>
decltype(auto) constexpr get (record< Ts... > &&r) noexcept
template<str L, typename... Ts>
decltype(auto) constexpr get (record< Ts... > const &r) noexcept
template<str L, typename... Ts>
decltype(auto) constexpr get (record< Ts... > const &&r) noexcept
template<concepts::identifier auto Id, typename... Ts>
decltype(auto) constexpr get (record< Ts... > &r) noexcept
 Extracts the field identified by Id from a kumi::record if it exists.
template<concepts::identifier auto Id, typename... Ts>
decltype(auto) constexpr get (record< Ts... > &&r) noexcept
template<concepts::identifier auto Id, typename... Ts>
decltype(auto) constexpr get (record< Ts... > const &r) noexcept
template<concepts::identifier auto Id, typename... Ts>
decltype(auto) constexpr get (record< Ts... > const &&r) noexcept
template<typename T, typename... Ts>
decltype(auto) constexpr get (record< Ts... > &r) noexcept
 Extracts the field which underlying type is T from a kumi::record if it exist.
template<typename T, typename... Ts>
decltype(auto) constexpr get (record< Ts... > &&r) noexcept
template<typename T, typename... Ts>
decltype(auto) constexpr get (record< Ts... > const &r) noexcept
template<typename T, typename... Ts>
decltype(auto) constexpr get (record< Ts... > const &&r) noexcept