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

◆ operator[]() [1/4]

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

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

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

Example:

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
kumi::tuple t = { 1, 2.3, 4.5f, '@' };
// It is possible to have mixed nammed and unnamed fields
std::cout << t[ kumi::as<int>{} ] << "\n";
std::cout << t[ kumi::as<double>{} ] << "\n";
std::cout << t[ kumi::as<float>{} ] << "\n";
t[kumi::as<int>{}]++;
std::cout << t[kumi::as<int>{}] << "\n";
}
Lightweight type-wrapper.
Definition as.hpp:29
Fixed-size collection of heterogeneous values.
Definition tuple.hpp:33