KUMI v4.0.0
Flawless Fluorite
Loading...
Searching...
No Matches

◆ operator[]() [4/4]

template<typename... Ts>
template<kumi::str L>
requires (kumi::concepts::contains_label<kumi::label_t<L>, Ts...>)
decltype(auto) kumi::tuple< Ts >::operator[] ( kumi::label_t< L > s) &
inlineconstexprnoexcept

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

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

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::tuple t = { "x"_id = 1, 2.3, my_field = '@' };
std::cout << t << "\n";
std::cout << t["x"_l] << "\n";
std::cout << t["mystery"_l] << "\n";
t["mystery"_l]++;
std::cout << t["mystery"_l] << "\n";
}
identifier definition class
Definition identifier.hpp:86
friend constexpr kumi::str to_str(identifier< ID, Checker > const &)
A checked field str representation is the underlying type, checker is ignored.
Definition identifier.hpp:91
Static string used to create named fields.
Definition str.hpp:24
Fixed-size collection of heterogeneous values.
Definition tuple.hpp:33