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

◆ operator[]() [2/4]

template<typename... Ts>
template<concepts::identifier Id>
requires (concepts::uniquely_named<Ts...> && concepts::contains_field<Id, Ts...>)
decltype(auto) kumi::tuple< Ts >::operator[] ( Id const & ) &
inlineconstexprnoexcept

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

Note
Does not participate in overload resolution if there are no field which identifier matches Id in the tuple or if the tuple contains duplicate identifiers.
Template Parameters
IdIdentifier of the element to access
Returns
A reference to the selected element of current tuple.

Example:

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
using namespace kumi::literals;
kumi::tuple t = { "x"_id = 1, "y"_id = 2.3, "z"_id = 4.5f, "t"_id = '@' };
std::cout << t << "\n";
std::cout << t["x"_id] << "\n";
std::cout << t["y"_id] << "\n";
std::cout << t["z"_id] << "\n";
t["t"_id]++;
std::cout << t["t"_id] << "\n";
}
Fixed-size collection of heterogeneous values.
Definition tuple.hpp:33