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

◆ operator[]() [4/4]

template<typename... Ts>
template<str Name>
requires (concepts::contains_label<label_t<Name>, Ts...>)
decltype(auto) kumi::record< Ts >::operator[] ( 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:86
friend constexpr str to_str(identifier< ID, Checker > const &)
A checked field str representation is the underlying type, checker is ignored.
Definition identifier.hpp:91
Fixed-size collection of heterogeneous tagged fields, tags are unique.
Definition record.hpp:36
Static string used to create named fields.
Definition str.hpp:24