cxxomfort  rel.20211024
Simple backports for C++ - https://ryan.gulix.cl/fossil.cgi/cxxomfort/
Classes | Namespaces
library/tuple.hpp File Reference

Classes

struct  tuple2function_t< Ret, Tuple >
 Convert from tuple type to function signature.Given a tuple of the form T<T1,T2,...>, obtain a function signature Ret(T1,T2,...) More...
 
struct  function2tuple_t< FnSig >
 Convert from function signature type to tuple type.Given a function signature R(T1,T2,...), obtain a tuple of the form T<T1,T2,...> More...
 

Namespaces

 cxxomfort
 Namespace of the cxxomfort library.
 
 cxxomfort::library
 Supplements to backports and other utilities.
 

Functions

template<typename T , typename... TArgs>
std::tuple< T, Targs... > tuple_unshift (T const &t0, std::tuple< TArgs... > const &tu)
 Returns a tuple with an extra element at the beginning. More...
 
template<typename T , typename... TArgs>
std::tuple< Targs..., T > tuple_push (T const &t0, std::tuple< TArgs... > const &tu)
 Returns a tuple with an extra element at the end. More...
 
template<typename... TArgs, typename First >
std::tuple< TArgs... > tuple_shift (std::tuple< TFirst, TArgs... > const &tu)
 Removes the first type from a tuple. More...
 
template<typename... TArgs, typename TLast >
std::tuple< TArgs... > tuple_pop (std::tuple< TArgs..., TLast > const &tu)
 Removes the last type from a tuple. More...
 

Detailed Description

This file provides supplementary features for the tuple-related utilities present in <tuple>.

cxxo-sup-tuple

Interfaces brought from impl: is_tuple , tuple_count_type , tuple_index

All interfaces are defined in the namespace cxxomfort::algorithm::.

Function Documentation

◆ tuple_unshift()

std::tuple<T,Targs...> cxxomfort::library::tuple::tuple_unshift ( T const &  t0,
std::tuple< TArgs... > const &  tu 
)

Returns a tuple with an extra element at the beginning.

Parameters
vAn element to be added to a tuple.
tuA std::tuple of N elements.
Returns
A std::tuple of N+1 elements { v, tu_0, ... } .
Exceptions
Whatevermake_tuple throws.

Given a tuple tu and a value v , tuple_unshift creates a new tuple the element v and then the elements of tu .

auto tu1 = make_tuple("b"s, "c"s, false);
auto tu2 = tuple_unshift("a"s, tu1);
assert (tu2 == make_tuple("a"s, "b"s, "c"s, false) );

◆ tuple_push()

std::tuple<Targs...,T> cxxomfort::library::tuple::tuple_push ( T const &  t0,
std::tuple< TArgs... > const &  tu 
)

Returns a tuple with an extra element at the end.

Parameters
vAn element to be added to a tuple.
tuA std::tuple of N elements.
Returns
A std::tuple of N+1 elements { tu_0, ... , v }.
Exceptions
Whatevermake_tuple throws.

Given a tuple tu and a value v , tuple_push creates a new tuple with the elements of tu and then the element v .

auto tu1 = make_tuple(1, 2.0, "3.0");
auto tu2 = tuple_push(true, tu1);
assert (tu2 == make_tuple(1, 2.0, "3.0", true) );

◆ tuple_shift()

std::tuple<TArgs...> cxxomfort::library::tuple::tuple_shift ( std::tuple< TFirst, TArgs... > const &  tu)

Removes the first type from a tuple.

Parameters
tuA std::tuple of N+1 elements.
Returns
A tuple of N elements.
Exceptions
Whatevermake_tuple throws.

Given a tuple tu , tuple_shift creates a new tuple with copies of all but the first element from the original tuple.

If tu is a tuple with only one element, tuple_shift errors at compile-time from trying to build an empty tuple.

In C++03, tuple_shift works with tuples of up to six (6) (seis) types.

auto tu1 = make_tuple(1, 'a', 'b', "c", 2);
auto tu2 = tuple_shift(tu1);
assert (tu2 == make_tuple('a', 'b', "c", 2) );

◆ tuple_pop()

std::tuple<TArgs...> cxxomfort::library::tuple::tuple_pop ( std::tuple< TArgs..., TLast > const &  tu)

Removes the last type from a tuple.

Parameters
tuA std::tuple of N+1 elements.
Returns
A tuple of N elements.
Exceptions
Whatevermake_tuple throws.

Given a tuple tu , tuple_pop creates a new tuple with copies of all but the last element from the original tuple.

If tu is a tuple with only one element, tuple_pop returns an empty tuple.

In C++03, tuple_pop works with tuples of up to six (6) (seis) types.

auto tu1 = make_tuple(1, 'a', 'b', "c", 2);
auto tu2 = tuple_pop(tu1);
assert (tu2 == make_tuple(1, 'a', 'b', "c") );