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 \( (A \times B) \)

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';
}
decltype(auto) constexpr get(record< Ts... > &r) noexcept
Extracts the Ith field from a kumi::record.
Definition record.hpp:766
Fixed-size collection of heterogeneous values.
Definition tuple.hpp:35

Public Member Functions

template<typename... Us>
constexpr tupleoperator= (tuple< Us... > &&other)
 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>
constexpr tupleoperator= (tuple< Us... > const &other)
 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...>>)
constexpr operator tuple< Us... > () 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...>>)
constexpr operator tuple< Us... > ()
 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
static constexpr bool empty () noexcept
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

Comparison operators
template<typename... Us>
constexpr auto operator== (tuple const &self, tuple< Us... > const &other) noexcept
 Compares a tuple with another for equality.
template<typename... Us>
constexpr auto operator!= (tuple const &self, tuple< Us... > const &other) noexcept
 Compares a tuple with another for inequality.
template<typename... Us>
requires (sizeof...(Ts) == sizeof...(Us))
constexpr auto operator< (tuple const &lhs, tuple< Us... > const &rhs) noexcept
 Compares tuples for the lexicographical less-than relation.
template<typename... Us>
requires requires { rhs < lhs; }
constexpr auto operator<= (tuple const &lhs, tuple< Us... > const &rhs) noexcept
 Compares tuples for the lexicographical less-than-or-equal relation.
template<typename... Us>
requires requires { rhs < lhs; }
constexpr auto operator> (tuple const &lhs, tuple< Us... > const &rhs) noexcept
 Compares tuples for the lexicographical greater-than relation.
template<typename... Us>
requires requires { lhs < rhs; }
constexpr auto operator>= (tuple const &lhs, tuple< Us... > const &rhs) noexcept
 Compares tuples for the lexicographical greater-than-or-equal relation.

(Note that these are not member symbols.)

template<typename CharT, typename Traits>
std::basic_ostream< CharT, Traits > & operator<< (std::basic_ostream< CharT, Traits > &os, tuple const &t) noexcept
 Inserts a kumi::tuple in an output stream.
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