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

◆ operator[]() [1/4]

template<typename... Ts>
template<typename T>
requires (concepts::uniquely_typed<kumi_implementation_defined...> && concepts::contains_type<T, kumi_implementation_defined...>)
decltype(auto) kumi::record< Ts >::operator[] ( 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
Fixed-size collection of heterogeneous tagged fields, tags are unique.
Definition record.hpp:36