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

Fixed-size collection of heterogeneous fields with distinct labels. More...

#include <kumi/product_types/record.hpp>

Detailed Description

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

Fixed-size collection of heterogeneous fields with distinct labels.

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

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_as_record<"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(array< T, N > &t) noexcept
Extracts the Ith element from a kumi::array.
Definition array.hpp:672
Fixed-size collection of heterogeneous fields with distinct labels.
Definition record.hpp:36

Public Member Functions

template<typename... Us>
requires ( kumi::concepts::equivalent<record, record<Us...>> && (std::is_assignable_v<typename Ts::type&, std::remove_reference_t<kumi::field_of_t<Ts, record<Us...>>>&&> && ...))
constexpr record & operator= (record< Us... > &&other) noexcept((std::is_nothrow_assignable_v< typename Ts::type &, std::remove_reference_t< kumi::field_of_t< Ts, record< Us... > > > && > &&...))
 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 ( kumi::concepts::equivalent<record, record<Us...>> && (std::is_assignable_v<typename Ts::type&, std::remove_reference_t<kumi::field_of_t<Ts, record<Us...>>> const&> && ...))
constexpr record & operator= (record< Us... > const &other) noexcept((std::is_nothrow_assignable_v< typename Ts::type &, std::remove_reference_t< kumi::field_of_t< Ts, record< Us... > > > const & > &&...))
 Replaces the content of the record with the content of another record.
Accessors
template<std::size_t I>
requires (I < sizeof...(Ts))
constexpr decltype(auto) operator[] (kumi::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[] (kumi::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[] (kumi::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[] (kumi::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 (kumi::concepts::uniquely_typed<kumi_implementation_defined...> && kumi::concepts::contains_type<T, kumi_implementation_defined...>)
constexpr decltype(auto) operator[] (kumi::as< T > type) &noexcept
 Extracts the element with type T from a kumi::record.
template<typename T>
requires (kumi::concepts::uniquely_typed<kumi_implementation_defined...> && kumi::concepts::contains_type<T, kumi_implementation_defined...>)
constexpr decltype(auto) operator[] (kumi::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 (kumi::concepts::uniquely_typed<kumi_implementation_defined...> && kumi::concepts::contains_type<T, kumi_implementation_defined...>)
constexpr decltype(auto) operator[] (kumi::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 (kumi::concepts::uniquely_typed<kumi_implementation_defined...> && kumi::concepts::contains_type<T, kumi_implementation_defined...>)
constexpr decltype(auto) operator[] (kumi::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<kumi::str Name>
requires (kumi::concepts::contains_label<kumi::label_t<Name>, Ts...>)
constexpr decltype(auto) operator[] (kumi::label_t< Name > l) &noexcept
 Extracts the element of the field labeled L from a kumi::record.
template<kumi::str Name>
requires (kumi::concepts::contains_label<kumi::label_t<Name>, Ts...>)
constexpr decltype(auto) operator[] (kumi::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<kumi::str Name>
requires (kumi::concepts::contains_label<kumi::label_t<Name>, Ts...>)
constexpr decltype(auto) operator[] (kumi::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<kumi::str Name>
requires (kumi::concepts::contains_label<kumi::label_t<Name>, Ts...>)
constexpr decltype(auto) operator[] (kumi::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<kumi::concepts::identifier Id>
requires (kumi::concepts::contains_identifier<Id, Ts...>)
constexpr decltype(auto) operator[] (Id const &) &noexcept
 Extracts the element whose identifier matches Id from a kumi::record.
template<kumi::concepts::identifier Id>
requires (kumi::concepts::contains_identifier<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<kumi::concepts::identifier Id>
requires (kumi::concepts::contains_identifier<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<kumi::concepts::identifier Id>
requires (kumi::concepts::contains_identifier<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.

Friends

constexpr void swap (record &a, record &b) noexcept((std::is_nothrow_swappable_v< kumi_implementation_defined > &&...))
 Swaps the fields of two kumi::records.

(Note that these are not member symbols.)

template<typename CharT, typename Traits, typename... Ts>
std::basic_ostream< CharT, Traits > & operator<< (std::basic_ostream< CharT, Traits > &os, record< Ts... > const &t) noexcept
 Inserts a kumi::record in an output stream.
template<typename... Ts, typename... Us>
constexpr auto operator== (record< Ts... > const &self, record< Us... > const &other) noexcept
 Compares a record with another for equality.
template<typename... Ts, typename... Us>
constexpr auto operator!= (record< Ts... > const &self, record< Us... > const &other) noexcept
 Compares a record with another for inequality.
template<typename... Ts>
 record (Ts &&...) -> record< std::unwrap_ref_decay_t< Ts >... >
 kumi::record deduction guide
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<kumi::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<kumi::str L, typename... Ts>
decltype(auto) constexpr get (record< Ts... > &&r) noexcept
template<kumi::str L, typename... Ts>
decltype(auto) constexpr get (record< Ts... > const &r) noexcept
template<kumi::str L, typename... Ts>
decltype(auto) constexpr get (record< Ts... > const &&r) noexcept
template<kumi::concepts::identifier auto Id, typename... Ts>
decltype(auto) constexpr get (record< Ts... > &r) noexcept
 Extracts the element of the field identified by Id from a kumi::record if it exists.
template<kumi::concepts::identifier auto Id, typename... Ts>
decltype(auto) constexpr get (record< Ts... > &&r) noexcept
template<kumi::concepts::identifier auto Id, typename... Ts>
decltype(auto) constexpr get (record< Ts... > const &r) noexcept
template<kumi::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 element of the field whose underlying type is T from a kumi::record if it exists.
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

Properties

constexpr auto values () noexcept
 Returns references to the values of the elements 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
 Returns the number of elements in a kumi::record.
static constexpr bool empty () noexcept
 Returns true if a kumi::record contains 0 elements.
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.

Member Function Documentation

◆ operator=()

template<typename... Ts>
template<typename... Us>
requires ( kumi::concepts::equivalent<record, record<Us...>> && (std::is_assignable_v<typename Ts::type&, std::remove_reference_t<kumi::field_of_t<Ts, record<Us...>>> const&> && ...))
record & kumi::record< Ts >::operator= ( record< Us... > const & other)
inlineconstexprnoexcept

Replaces the content of the record with the content of another record.

Parameters
otherkumi::record to copy or move from
Returns
*this
Note
This function does not participate in overload resolution if the fields in each record do not match or if the types between two matching fields do not match.

◆ operator[]() [1/4]

template<typename... Ts>
decltype(auto) kumi::record< Ts >::operator[] ( Id const & ) &
inlineconstexprnoexcept

Extracts the element whose identifier matches Id from a kumi::record.

Note
Does not participate in overload resolution if no field whose identifier matches Id is present in the record.
Template Parameters
IdIdentifier of the element to access
Returns
A reference to the selected element of current record.

Example:

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
using namespace kumi::literals;
kumi::record r = { "x"_id = 1, "y"_id = 2.3, "z"_id = 4.5f, "t"_id = '@' };
std::cout << r << "\n";
std::cout << r["x"_id] << "\n";
std::cout << r["y"_id] << "\n";
std::cout << r["z"_id] << "\n";
r["t"_id]++;
std::cout << r["t"_id] << "\n";
}

◆ operator[]() [2/4]

template<typename... Ts>
template<typename T>
requires (kumi::concepts::uniquely_typed<kumi_implementation_defined...> && kumi::concepts::contains_type<T, kumi_implementation_defined...>)
decltype(auto) kumi::record< Ts >::operator[] ( kumi::as< T > type) &
inlineconstexprnoexcept

Extracts the element with type T from a kumi::record.

Note
Does not participate in overload resolution if T is not present in the record or if the record contains duplicate types
Parameters
typeThe type to access in the record
Returns
A reference to the selected element of current record.

Example:

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
using namespace kumi::literals;
kumi::record r = { "a"_id=1,"b"_id=2.3,"c"_id=4.5f, "d"_id='@' };
std::cout << r[ kumi::as<int>{} ] << "\n";
std::cout << r[ kumi::as<double>{} ] << "\n";
std::cout << r[ kumi::as<float>{} ] << "\n";
r[kumi::as<int>{}]++;
std::cout << r[kumi::as<int>{}] << "\n";
}
Lightweight type-wrapper.
Definition as.hpp:29

◆ operator[]() [3/4]

template<typename... Ts>
template<std::size_t I>
requires (I < sizeof...(Ts))
decltype(auto) kumi::record< Ts >::operator[] ( kumi::index_t< I > i) &
inlineconstexprnoexcept

Extracts the Ith field from a kumi::record.

Note
Does not participate in overload resolution if I is not in [0, sizeof...(Ts)).
Parameters
iCompile-time index of the field to access
Returns
A reference to the selected field of current record.

Example:

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
using namespace kumi::literals;
kumi::record r = { "x"_id = 1, "y"_id = 2.3, "z"_id = 4.5f, "t"_id = '@' };
std::cout << r[0_c] << "\n";
std::cout << r[1_c] << "\n";
std::cout << r[2_c] << "\n";
r[3_c].value++;
std::cout << r[kumi::index<3>] << "\n";
}

◆ operator[]() [4/4]

template<typename... Ts>
template<kumi::str Name>
requires (kumi::concepts::contains_label<kumi::label_t<Name>, Ts...>)
decltype(auto) kumi::record< Ts >::operator[] ( kumi::label_t< Name > l) &
inlineconstexprnoexcept

Extracts the element of the field labeled L from a kumi::record.

Note
Does not participate in overload resolution if the label is not present in the record
Parameters
llabel of the field to access
Returns
A reference to the element of the selected field of current record.

Example:

#include <kumi/kumi.hpp>
#include <iostream>
struct my_id : kumi::identifier<my_id>
{
using parent = kumi::identifier<my_id>;
using parent::operator=;
friend constexpr auto to_str(my_id) { return kumi::str{"mystery"}; }
};
inline constexpr my_id my_field{};
int main()
{
using namespace kumi::literals;
kumi::record r = { "x"_id = 1, "y"_id = 2.3, my_field = '@' };
std::cout << r << "\n";
std::cout << r["x"_l] << "\n";
std::cout << r["y"_l] << "\n";
std::cout << r["mystery"_l] << "\n";
r["mystery"_l]++;
std::cout << r["mystery"_l] << "\n";
}
identifier definition class
Definition identifier.hpp:89
friend constexpr kumi_implementation_defined auto to_str(identifier const &)
A checked field str representation is the underlying type, checker is ignored.
Definition identifier.hpp:94
Static string used to create named fields.
Definition str.hpp:31

◆ get() [1/16]

template<typename T, typename... Ts>
decltype(auto) constexpr get ( record< Ts... > && r)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get() [2/16]

template<kumi::concepts::identifier auto Id, typename... Ts>
decltype(auto) constexpr get ( record< Ts... > && r)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get() [3/16]

template<kumi::str L, typename... Ts>
decltype(auto) constexpr get ( record< Ts... > && r)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get() [4/16]

template<std::size_t I, typename... Ts>
decltype(auto) constexpr get ( record< Ts... > && r)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get() [5/16]

template<typename T, typename... Ts>
decltype(auto) constexpr get ( record< Ts... > & r)
relatednodiscardinlineconstexprnoexcept

Extracts the element of the field whose underlying type is T from a kumi::record if it exists.

Note
Does not participate in overload resolution if the types are not unique
Template Parameters
TType of the element to access
Parameters
rRecord to index
Returns
A reference to the selected element of r.

Example:

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
using namespace kumi::literals;
kumi::record r = {"a"_id=1, "b"_id=2.3, "c"_id=4.5f, "d"_id='@' };
std::cout << kumi::get<int>(r) << "\n";
std::cout << kumi::get<double>(r) << "\n";
std::cout << kumi::get<float>(r) << "\n";
std::cout << kumi::get<char>(r) << "\n";
}

◆ get() [6/16]

template<kumi::concepts::identifier auto Id, typename... Ts>
decltype(auto) constexpr get ( record< Ts... > & r)
relatednodiscardinlineconstexprnoexcept

Extracts the element of the field identified by Id from a kumi::record if it exists.

Note
Does not participate in overload resolution if the names are not unique
Template Parameters
IdNon type template parameter identifier of the element to access
Parameters
rRecord to index
Returns
A reference to the selected element of r.

Example:

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
using namespace kumi::literals;
kumi::record r = { "x"_id = 1, "y"_id = 2.3, "z"_id = 4.5f, "t"_id = '@' };
std::cout << r["x"_id] << "\n";
std::cout << kumi::get<"x"_id>(r) << "\n";
std::cout << kumi::get<"y"_id>(r) << "\n";
std::cout << kumi::get<"z"_id>(r) << "\n";
kumi::get<"t"_id>(r)++;
std::cout << kumi::get<"t"_id>(r) << "\n";
}

◆ get() [7/16]

template<kumi::str L, typename... Ts>
decltype(auto) constexpr get ( record< Ts... > & r)
relatednodiscardinlineconstexprnoexcept

Extracts the element of the field labeled L from a kumi::record if it exists.

Note
Does not participate in overload resolution if the names are not unique
Template Parameters
LNon type template parameter label of the field to access
Parameters
rRecord to index
Returns
A reference to the element of the selected field of r.

Example:

#include <kumi/kumi.hpp>
#include <iostream>
struct my_id : kumi::identifier<my_id>
{
using parent = kumi::identifier<my_id>;
using parent::operator=;
friend constexpr auto to_str(my_id) { return kumi::str{"mystery"}; }
};
inline constexpr my_id my_field{};
int main()
{
using namespace kumi::literals;
kumi::record r = { "x"_id = 1, "y"_id = 2.3, my_field = '@' };
std::cout << r << "\n";
std::cout << kumi::get<"x">(r) << "\n";
std::cout << kumi::get<"y">(r) << "\n";
std::cout << kumi::get<"mystery">(r) << "\n";
kumi::get<"mystery">(r)++;
std::cout << kumi::get<"mystery">(r) << "\n";
}

◆ get() [8/16]

template<std::size_t I, typename... Ts>
decltype(auto) constexpr get ( record< Ts... > & r)
relatednodiscardinlineconstexprnoexcept

Extracts the Ith field from a kumi::record.

Note
Does not participate in overload resolution if I is not in [0, sizeof...(Ts)).
Template Parameters
ICompile-time index of the field to access
Parameters
rRecord to index
Returns
A reference to the selected field of r.

Example:

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
using namespace kumi::literals;
kumi::record r = { "x"_id = 1, "y"_id = 2.3, "z"_id = 4.5f, "t"_id = '@' };
std::cout << kumi::get<0>(r) << "\n";
std::cout << kumi::get<1>(r) << "\n";
std::cout << kumi::get<2>(r) << "\n";
kumi::get<3>(r).value++;
std::cout << kumi::get<3>(r) << "\n";
}

◆ get() [9/16]

template<typename T, typename... Ts>
decltype(auto) constexpr get ( record< Ts... > const && r)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get() [10/16]

template<kumi::concepts::identifier auto Id, typename... Ts>
decltype(auto) constexpr get ( record< Ts... > const && r)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get() [11/16]

template<kumi::str L, typename... Ts>
decltype(auto) constexpr get ( record< Ts... > const && r)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get() [12/16]

template<std::size_t I, typename... Ts>
decltype(auto) constexpr get ( record< Ts... > const && r)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get() [13/16]

template<typename T, typename... Ts>
decltype(auto) constexpr get ( record< Ts... > const & r)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get() [14/16]

template<kumi::concepts::identifier auto Id, typename... Ts>
decltype(auto) constexpr get ( record< Ts... > const & r)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get() [15/16]

template<kumi::str L, typename... Ts>
decltype(auto) constexpr get ( record< Ts... > const & r)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get() [16/16]

template<std::size_t I, typename... Ts>
decltype(auto) constexpr get ( record< Ts... > const & r)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ record()

template<typename... Ts>
record ( Ts && ...) -> record< std::unwrap_ref_decay_t< Ts >... >
related

kumi::record deduction guide

Template Parameters
TsType lists to build the record with.

◆ swap

template<typename... Ts>
void swap ( record< Ts > & a,
record< Ts > & b )
friend

Swaps the fields of two kumi::records.

See also
Callable with the usual using std::swap; swap(a, b) idiom, exchanges every matching field through ADL and does not participate in overload resolution if a field is not swappable.