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

◆ operator[]() [1/3]

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

Extracts the Ith element 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
Template Parameters
Tthe type to access in the tuple
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 = { 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:25
Fixed-size collection of heterogeneous values.
Definition tuple.hpp:37