KUMI v5.0.0
Gorgeous Garnet
Loading...
Searching...
No Matches

Fixed-size collection of heterogeneous values. More...

#include <kumi/product_types/tuple.hpp>

Detailed Description

template<typename... Ts>
class kumi::tuple< Ts >

Fixed-size collection of heterogeneous values.

kumi::tuple provides an aggregate based implementation of a tuple. It provides algorithms and functions designed to facilitate tuple's handling and transformations.

kumi::tuple is also compatible with standard tuple operations and structured bindings.

Template Parameters
TsSequence of types stored inside kumi::tuple.
See also
Product Type

Example:

#include <iostream>
#include <stdexcept>
#include <string>
#include <kumi/kumi.hpp>
{
switch (id)
{
case 0: return {3.8, 'A', "Lisa Simpson"};
case 1: return {2.9, 'C', "Milhouse Van Houten"};
case 2: return {1.7, 'D', "Ralph Wiggum"};
case 3: return {0.6, 'F', "Bart Simpson"};
}
throw std::invalid_argument("id");
}
int main()
{
const auto student0 = get_student(0);
std::cout << "ID: 0, "
<< "GPA: " << kumi::get<0>(student0) << ", "
<< "grade: " << kumi::get<1>(student0) << ", "
<< "name: " << kumi::get<2>(student0) << '\n';
const auto student1 = get_student(1);
std::cout << "ID: 1, "
<< "GPA: " << kumi::get<double>(student1) << ", "
<< "grade: " << kumi::get<char>(student1) << ", "
<< "name: " << kumi::get<std::string>(student1) << '\n';
double gpa2;
char grade2;
std::string name2;
kumi::tie(gpa2, grade2, name2) = get_student(2);
std::cout << "ID: 2, "
<< "GPA: " << gpa2 << ", "
<< "grade: " << grade2 << ", "
<< "name: " << name2 << '\n';
// C++17 structured binding:
const auto [gpa3, grade3, name3] = get_student(3);
std::cout << "ID: 3, "
<< "GPA: " << gpa3 << ", "
<< "grade: " << grade3 << ", "
<< "name: " << name3 << '\n';
}
constexpr tie_t tie
Definition tuple.hpp:540
decltype(auto) constexpr get(array< T, N > &t) noexcept
Extracts the Ith element from a kumi::array.
Definition array.hpp:672
Fixed-size collection of heterogeneous values.
Definition tuple.hpp:35

Public Member Functions

template<typename... Us>
requires (sizeof...(Ts) == sizeof...(Us)) && ((std::is_assignable_v<Ts&, Us&&> && ...))
constexpr tuple & operator= (tuple< Us... > &&other) noexcept((std::is_nothrow_assignable_v< Ts &, Us && > &&...))
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<typename... Us>
requires (sizeof...(Ts) == sizeof...(Us)) && ((std::is_assignable_v<Ts&, Us const&> && ...))
constexpr tuple & operator= (tuple< Us... > const &other) noexcept((std::is_nothrow_assignable_v< Ts &, Us const & > &&...))
 Replaces the contents of the tuple with the contents of another tuple.
Accessors
template<std::size_t I>
requires (I < sizeof...(Ts))
constexpr decltype(auto) operator[] (kumi::index_t< I > i) &noexcept
 Extracts the Ith element from a kumi::tuple.
template<std::size_t I>
requires (I < sizeof...(Ts))
constexpr decltype(auto) operator[] (kumi::index_t< I >) &&noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<std::size_t I>
requires (I < sizeof...(Ts))
constexpr decltype(auto) operator[] (kumi::index_t< I >) const &&noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<std::size_t I>
requires (I < sizeof...(Ts))
constexpr decltype(auto) operator[] (kumi::index_t< I >) const &noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<typename T>
requires (kumi::concepts::uniquely_typed<Ts...> && kumi::concepts::contains_type<T, Ts...>)
constexpr decltype(auto) operator[] (kumi::as< T > type) &noexcept
 Extracts the element with type T from a kumi::tuple.
template<typename T>
requires (kumi::concepts::uniquely_typed<Ts...> && kumi::concepts::contains_type<T, Ts...>)
constexpr decltype(auto) operator[] (kumi::as< T >) &&noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<typename T>
requires (kumi::concepts::uniquely_typed<Ts...> && kumi::concepts::contains_type<T, Ts...>)
constexpr decltype(auto) operator[] (kumi::as< T >) const &&noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<typename T>
requires (kumi::concepts::uniquely_typed<Ts...> && kumi::concepts::contains_type<T, Ts...>)
constexpr decltype(auto) operator[] (kumi::as< T >) const &noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<kumi::str L>
requires (kumi::concepts::contains_label<kumi::label_t<L>, Ts...>)
constexpr decltype(auto) operator[] (kumi::label_t< L > s) &noexcept
 Extracts the element of the field labeled L from a kumi::tuple.
template<kumi::str L>
requires (kumi::concepts::contains_label<kumi::label_t<L>, Ts...>)
constexpr decltype(auto) operator[] (kumi::label_t< L >) &&noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<kumi::str L>
requires (kumi::concepts::contains_label<kumi::label_t<L>, Ts...>)
constexpr decltype(auto) operator[] (kumi::label_t< L >) const &&noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<kumi::str L>
requires (kumi::concepts::contains_label<kumi::label_t<L>, Ts...>)
constexpr decltype(auto) operator[] (kumi::label_t< L >) const &noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<kumi::concepts::identifier Id>
requires (kumi::concepts::uniquely_named<Ts...> && kumi::concepts::contains_identifier<Id, Ts...>)
constexpr decltype(auto) operator[] (Id const &) &noexcept
 Extracts the element whose identifier matches Id from a kumi::tuple.
template<kumi::concepts::identifier Id>
requires (kumi::concepts::uniquely_named<Ts...> && kumi::concepts::contains_identifier<Id, Ts...>)
constexpr decltype(auto) operator[] (Id const &) &&noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<kumi::concepts::identifier Id>
requires (kumi::concepts::uniquely_named<Ts...> && kumi::concepts::contains_identifier<Id, Ts...>)
constexpr decltype(auto) operator[] (Id const &) const &&noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<kumi::concepts::identifier Id>
requires (kumi::concepts::uniquely_named<Ts...> && kumi::concepts::contains_identifier<Id, Ts...>)
constexpr decltype(auto) operator[] (Id const &) const &noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Conversions
template<typename... Us>
requires (sizeof...(Us) == sizeof...(Ts)) && (!std::same_as<tuple<Ts...>, tuple<Us...>>) && ((std::is_constructible_v<Us, Ts const&> && ...))
 explicit (!(std::is_convertible_v< Ts const &, Us > &&...)) const expr operator tuple< Us... >() const noexcept((std::is_nothrow_constructible_v< Us, Ts const & > &&...))
 Enables static casting a tuple<Ts...> to a tuple<Us...>, the conversion is explicit if the casting requires internal explicit conversions.
template<typename... Us>
requires (sizeof...(Us) == sizeof...(Ts)) && (!std::same_as<tuple<Ts...>, tuple<Us...>>) && ((std::is_constructible_v<Us, Ts&> && ...))
 explicit (!(std::is_convertible_v< Ts &, Us > &&...)) const expr operator tuple< Us... >() noexcept((std::is_nothrow_constructible_v< Us, Ts & > &&...))
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Static Public Member Functions

Properties
static constexpr auto size () noexcept
 Returns the number of elements in a kumi::tuple.
static constexpr bool empty () noexcept
 Returns true if a kumi::tuple contains 0 elements.
static constexpr auto identifiers () noexcept
 Returns the identifiers associated to the elements of a kumi::tuple.
static constexpr auto labels () noexcept
 Returns the labels associated to the elements of a kumi::tuple.

Friends

constexpr void swap (tuple &a, tuple &b) noexcept((std::is_nothrow_swappable_v< Ts > &&...))
 Swaps the contents of two kumi::tuples.

(Note that these are not member symbols.)

template<typename CharT, typename Traits, typename... Ts>
std::basic_ostream< CharT, Traits > & operator<< (std::basic_ostream< CharT, Traits > &os, tuple< Ts... > const &t) noexcept
 Inserts a kumi::tuple in an output stream.
template<typename... Ts, typename... Us>
constexpr auto operator== (tuple< Ts... > const &self, tuple< Us... > const &other) noexcept
 Compares a tuple with another for equality.
template<typename... Ts, typename... Us>
constexpr auto operator!= (tuple< Ts... > const &self, tuple< Us... > const &other) noexcept
 Compares a tuple with another for inequality.
template<typename... Ts, typename... Us>
constexpr auto operator< (tuple< Ts... > const &lhs, tuple< Us... > const &rhs) noexcept
 Compares tuples for the lexicographical less-than relation.
template<typename... Ts, typename... Us>
constexpr auto operator<= (tuple< Ts... > const &lhs, tuple< Us... > const &rhs) noexcept
 Compares tuples for the lexicographical less-than-or-equal relation.
template<typename... Ts, typename... Us>
constexpr auto operator> (tuple< Ts... > const &lhs, tuple< Us... > const &rhs) noexcept
 Compares tuples for the lexicographical greater-than relation.
template<typename... Ts, typename... Us>
constexpr auto operator>= (tuple< Ts... > const &lhs, tuple< Us... > const &rhs) noexcept
 Compares tuples for the lexicographical greater-than-or-equal relation.
template<typename... Ts>
 tuple (Ts &&...) -> tuple< std::unwrap_ref_decay_t< Ts >... >
 kumi::tuple deduction guide
template<std::size_t I, typename... Ts>
decltype(auto) constexpr get (tuple< Ts... > &t) noexcept
 Extracts the Ith element from a kumi::tuple.
template<std::size_t I, typename... Ts>
decltype(auto) constexpr get (tuple< Ts... > &&arg) noexcept
template<std::size_t I, typename... Ts>
decltype(auto) constexpr get (tuple< Ts... > const &arg) noexcept
template<std::size_t I, typename... Ts>
decltype(auto) constexpr get (tuple< Ts... > const &&arg) noexcept
template<kumi::str L, typename... Ts>
decltype(auto) constexpr get (tuple< Ts... > &t) noexcept
 Extracts the field labeled L from a kumi::tuple if it exists.
template<kumi::str L, typename... Ts>
decltype(auto) constexpr get (tuple< Ts... > &&t) noexcept
template<kumi::str L, typename... Ts>
decltype(auto) constexpr get (tuple< Ts... > const &t) noexcept
template<kumi::str L, typename... Ts>
decltype(auto) constexpr get (tuple< Ts... > const &&t) noexcept
template<kumi::concepts::identifier auto Id, typename... Ts>
decltype(auto) constexpr get (tuple< Ts... > &t) noexcept
 Extracts the field identified by Id from a kumi::tuple if it exists.
template<kumi::concepts::identifier auto Id, typename... Ts>
decltype(auto) constexpr get (tuple< Ts... > &&t) noexcept
template<kumi::concepts::identifier auto Id, typename... Ts>
decltype(auto) constexpr get (tuple< Ts... > const &t) noexcept
template<kumi::concepts::identifier auto Id, typename... Ts>
decltype(auto) constexpr get (tuple< Ts... > const &&t) noexcept
template<typename T, typename... Ts>
decltype(auto) constexpr get (tuple< Ts... > &t) noexcept
 Extracts the field whose type is T from a kumi::tuple if it exists.
template<typename T, typename... Ts>
decltype(auto) constexpr get (tuple< Ts... > &&t) noexcept
template<typename T, typename... Ts>
decltype(auto) constexpr get (tuple< Ts... > const &t) noexcept
template<typename T, typename... Ts>
decltype(auto) constexpr get (tuple< Ts... > const &&t) noexcept

Member Function Documentation

◆ explicit()

template<typename... Ts>
template<typename... Us>
requires (sizeof...(Us) == sizeof...(Ts)) && (!std::same_as<tuple<Ts...>, tuple<Us...>>) && ((std::is_constructible_v<Us, Ts const&> && ...))
kumi::tuple< Ts >::explicit ( ! std::is_convertible_v< Ts const &, Us > &&...) const
inlinenoexceptexplicit

Enables static casting a tuple<Ts...> to a tuple<Us...>, the conversion is explicit if the casting requires internal explicit conversions.

Template Parameters
UsTypes composing the destination tuple
Note
This function does not participate in overload resolution if the target tuple cannot be constructed from the values of the source, if their size does not match or if they are the same type. The conversion is explicit if the conversion of some member to the target needs to be explicit.
EDG current implementation of explicit(bool) is broken so all conversions are implicit

This permits the conversion from a tuple<T>& to a tuple<T&> which makes it suitable for some zip-like cases such as building a structure of arrays iterator.

Example :

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
kumi::tuple a = { 65, 2.3, 4.5f};
auto b = static_cast<kumi::tuple<char,int,double>>(a);
std::cout << a << "\n";
std::cout << b << "\n";
}
#include <iostream>
#include <kumi/kumi.hpp>
#include <algorithm>
#include <ranges>
#include <vector>
template <class... Ts>
struct soa
{
struct iterator
{
using value_type = kumi::tuple<Ts...>;
soa* s;
std::size_t i;
auto operator==(iterator b) const -> bool { return i == b.i; }
auto operator<=>(iterator b) const { return i <=> b.i; }
auto operator++() ->iterator& { ++i; return *this; }
auto operator--() ->iterator& { --i; return *this; }
auto operator++(int) ->iterator { auto copy = *this; ++*this; return copy; }
auto operator--(int) ->iterator { auto copy = *this; --*this; return copy; }
friend auto operator+(iterator a, std::size_t b) -> iterator{ return {.s = a.s, .i = a.i + b}; }
friend auto operator+(std::size_t a, iterator b) -> iterator{ return {.s = b.s, .i = a + b.i}; }
friend auto operator-(iterator a, std::size_t b) -> iterator{ return {.s = a.s, .i = a.i - b}; }
friend auto operator-(std::size_t a, iterator b) -> iterator{ return {.s = b.s, .i = a - b.i}; }
auto operator+=(std::size_t b) -> iterator& { i += b; return *this; }
auto operator-=(std::size_t b) -> iterator& { i -= b; return *this; }
auto operator-(iterator b) const -> std::ptrdiff_t { return i - b.i; }
auto operator*() const
{
return kumi::apply([&](auto&... vs) { return kumi::tie(vs[i]...); }, s->fields);
}
auto operator[](std::ptrdiff_t b) const
{
return kumi::apply([&](auto&... vs) { return kumi::tie(vs[i + b]...); }, s->fields);
}
};
auto begin() -> iterator { return {.s = this, .i = 0 }; }
auto end() -> iterator { return {.s = this, .i = kumi::get<0>(fields).size() }; }
};
static_assert(std::random_access_iterator<soa<int>::iterator>);
int main()
{
soa<float,int> s;
get<0>(s.fields) = {1.2f,2.3f,3.4f,4.5f};
get<1>(s.fields) = {10,20,30,40};
for(auto e : s)
std::cout << e << "\n";
}
constexpr apply_t apply
Definition apply.hpp:105
constexpr auto operator==(tuple< Ts... > const &self, tuple< Us... > const &other) noexcept
Compares a tuple with another for equality.
Definition tuple.hpp:368

◆ operator=()

template<typename... Ts>
template<typename... Us>
requires (sizeof...(Ts) == sizeof...(Us)) && ((std::is_assignable_v<Ts&, Us const&> && ...))
tuple & kumi::tuple< Ts >::operator= ( tuple< Us... > const & other)
inlineconstexprnoexcept

Replaces the contents of the tuple with the contents of another tuple.

Parameters
otherkumi::tuple to copy or move from
Returns
*this
Note
This function does not participate in overload resolution if the members from the source tuple cannot be converted to the members of the current tuple.

◆ operator[]() [1/4]

template<typename... 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 no field whose identifier matches Id is present 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";
}

◆ operator[]() [2/4]

template<typename... Ts>
template<typename T>
requires (kumi::concepts::uniquely_typed<Ts...> && kumi::concepts::contains_type<T, Ts...>)
decltype(auto) kumi::tuple< Ts >::operator[] ( kumi::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

◆ operator[]() [3/4]

template<typename... Ts>
template<std::size_t I>
requires (I < sizeof...(Ts))
decltype(auto) kumi::tuple< Ts >::operator[] ( kumi::index_t< I > i) &
inlineconstexprnoexcept

Extracts the Ith element from a kumi::tuple.

Note
Does not participate in overload resolution if I is not in [0, sizeof...(Ts)).
Parameters
iCompile-time index 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 = { 1, 2.3, 4.5f, '@' };
std::cout << t[0_c] << "\n";
std::cout << t[1_c] << "\n";
std::cout << t[2_c] << "\n";
t[3_c]++;
std::cout << t[kumi::index<3>] << "\n";
}

◆ 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:89
friend constexpr kumi_implementation_defined auto to_str(identifier const &)
A checked field str representation is the underlying type, checker is ignored.
Definition identifier.hpp:94
Static string used to create named fields.
Definition str.hpp:31

◆ get() [1/16]

template<std::size_t I, typename... Ts>
decltype(auto) constexpr get ( tuple< Ts... > && arg)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get() [2/16]

template<typename T, typename... Ts>
decltype(auto) constexpr get ( tuple< Ts... > && t)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get() [3/16]

template<kumi::concepts::identifier auto Id, typename... Ts>
decltype(auto) constexpr get ( tuple< Ts... > && t)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get() [4/16]

template<kumi::str L, typename... Ts>
decltype(auto) constexpr get ( tuple< Ts... > && t)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get() [5/16]

template<typename T, typename... Ts>
decltype(auto) constexpr get ( tuple< Ts... > & t)
relatednodiscard

Extracts the field whose type is T from a kumi::tuple if it exists.

Note
Does not participate in overload resolution if the types are not unique
Template Parameters
TType of the element to access
Parameters
tTuple to index
Returns
A reference to the selected element of t.

inline constexpr noexcept

Example:

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
kumi::tuple t = { 1, 2.3, 4.5f, '@' };
std::cout << kumi::get<int>(t) << "\n";
std::cout << kumi::get<double>(t) << "\n";
std::cout << kumi::get<float>(t) << "\n";
std::cout << kumi::get<char>(t) << "\n";
}

◆ get() [6/16]

template<kumi::concepts::identifier auto Id, typename... Ts>
decltype(auto) constexpr get ( tuple< Ts... > & t)
relatednodiscardinlineconstexprnoexcept

Extracts the field identified by Id from a kumi::tuple if it exists.

Note
Does not participate in overload resolution if the names are not unique
Template Parameters
IdNon type template parameter identifier of the element to access
Parameters
tTuple to index
Returns
A reference to the selected element of t.

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["x"_id] << "\n";
std::cout << kumi::get<"x"_id>(t) << "\n";
std::cout << kumi::get<"y"_id>(t) << "\n";
std::cout << kumi::get<"z"_id>(t) << "\n";
kumi::get<"t"_id>(t)++;
std::cout << kumi::get<"t"_id>(t) << "\n";
}

◆ get() [7/16]

template<kumi::str L, typename... Ts>
decltype(auto) constexpr get ( tuple< Ts... > & t)
relatednodiscardinlineconstexprnoexcept

Extracts the field labeled L from a kumi::tuple if it exists.

Note
Does not participate in overload resolution if the names are not unique
Template Parameters
LNon type template parameter label of the element to access
Parameters
tTuple to index
Returns
A reference to the selected element of t.

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 << kumi::get<"x">(t) << "\n";
std::cout << kumi::get<"mystery">(t) << "\n";
kumi::get<"mystery">(t)++;
std::cout << kumi::get<"mystery">(t) << "\n";
}

◆ get() [8/16]

template<std::size_t I, typename... Ts>
decltype(auto) constexpr get ( tuple< Ts... > & t)
relatednodiscardinlineconstexprnoexcept

Extracts the Ith element from a kumi::tuple.

Note
Does not participate in overload resolution if I is not in [0, sizeof...(Ts)).
Template Parameters
ICompile-time index of the element to access
Parameters
tTuple to index
Returns
A reference to the selected element of t.

Example:

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
using namespace kumi::literals;
kumi::tuple t = { 1, 2.3, 4.5f, '@' };
std::cout << kumi::get<0>(t) << "\n";
std::cout << kumi::get<1>(t) << "\n";
std::cout << kumi::get<2>(t) << "\n";
std::cout << kumi::get<3>(t) << "\n";
}

◆ get() [9/16]

template<std::size_t I, typename... Ts>
decltype(auto) constexpr get ( tuple< Ts... > const && arg)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get() [10/16]

template<typename T, typename... Ts>
decltype(auto) constexpr get ( tuple< Ts... > const && t)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get() [11/16]

template<kumi::concepts::identifier auto Id, typename... Ts>
decltype(auto) constexpr get ( tuple< Ts... > const && t)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get() [12/16]

template<kumi::str L, typename... Ts>
decltype(auto) constexpr get ( tuple< Ts... > const && t)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get() [13/16]

template<std::size_t I, typename... Ts>
decltype(auto) constexpr get ( tuple< Ts... > const & arg)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get() [14/16]

template<typename T, typename... Ts>
decltype(auto) constexpr get ( tuple< Ts... > const & t)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get() [15/16]

template<kumi::concepts::identifier auto Id, typename... Ts>
decltype(auto) constexpr get ( tuple< Ts... > const & t)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get() [16/16]

template<kumi::str L, typename... Ts>
decltype(auto) constexpr get ( tuple< Ts... > const & t)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ operator<()

template<typename... Ts, typename... Us>
auto operator< ( tuple< Ts... > const & lhs,
tuple< Us... > const & rhs )
related

Compares tuples for the lexicographical less-than relation.

Note
This function does not participate in overload resolution if the tuples are not lexicographically ordered

◆ swap

template<typename... Ts>
void swap ( tuple< Ts > & a,
tuple< Ts > & b )
friend

Swaps the contents of two kumi::tuples.

Note
Does not participate in overload resolution if an element is not swappable.

◆ tuple()

template<typename... Ts>
tuple ( Ts && ...) -> tuple< std::unwrap_ref_decay_t< Ts >... >
related

kumi::tuple deduction guide

Template Parameters
TsType lists to build the tuple with.