Loading...
Searching...
No Matches
Tuple
Utility

Additional helper utilities for "tuple" types like std::tuple, std::pair, seqan3::pod_tuple that are not specific to a SeqAn module. More...

Collaboration diagram for Tuple:

## Classes

interface | pair_like
| Whether a type behaves like a tuple with exactly two elements. More...
struct | seqan3::pod_tuple< type0 >
| Recursion anchor for seqan3::pod_tuple. More...
struct | seqan3::pod_tuple< type0, types... >
| Behaves like std::tuple but is an aggregate PODType. More...
interface | tuple_like
| Whether a type behaves like a tuple. More...

## Typedefs

template<typename t1, typename t2>
using | seqan3::common_pair = seqan::stl::pair<t1, t2>
| A std::pair implementation that incorporates most changes from C++23's standard library.
template<typename... t>
using | seqan3::common_tuple = seqan::stl::tuple<t...>
| A std::tuple implementation that incorporates most changes from C++23's standard library.

## Functions

template<tuple_like tuple_t>
constexpr auto | seqan3::tuple_pop_front (tuple_t &&t)
| Removes the first element of a tuple.
template<typename pivot_t, tuple_like tuple_t>
constexpr auto | seqan3::tuple_split (tuple_t &&t)
| Splits a tuple like data structure at the first position of the given type.
template<size_t pivot_c, template< typename... > typename tuple_t, typename... ts> requires tuple_like<tuple_t<ts...>>
constexpr auto | seqan3::tuple_split (tuple_t< ts... > const &t)
| Splits a tuple like data structure at the given position.

## Detailed Description

Additional helper utilities for "tuple" types like std::tuple, std::pair, seqan3::pod_tuple that are not specific to a SeqAn module.

See also
  Utility

## Function Documentation

## tuple_pop_front()

template<tuple_like tuple_t>

auto seqan3::tuple_pop_front | ( | tuple_t && | t | ) |

constexpr

Removes the first element of a tuple.

Parameters

  [in] | t | The original tuple.

Returns
  A new tuple without the first element of t.

Note, that the tuple must contain at least one element and must support empty tuple types, i.e. std::pair cannot be used.

### Complexity

Linear in the number of elements.

### Thread safety

Concurrent invocations of this functions are thread safe.

## tuple_split() [1/2]

template<typename pivot_t, tuple_like tuple_t>

auto seqan3::tuple_split | ( | tuple_t && | t | ) |

constexpr

Splits a tuple like data structure at the first position of the given type.

Template Parameters

  pivot_t | A template type specifying the split position.

Parameters

  [in] | t | The original tuple to split.

Returns
  A new tuple of tuples with the left side of the split and the right side of the split.

Splits a tuple into two tuples, while the element at the split position will be contained in the second tuple. Note, that the returned tuples can be empty. For this reason it is not possible to use tuple like objects, that cannot be empty, i.e. std::pair. Using such an object will emit an compiler error.

### example

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <string>
#include <seqan3/utility/tuple/split.hpp>
int main()
{
// Split at position 2.
std::tuple<int, char, float, std::string> t{1, 'c', 0.3, "hello"};
auto [left, right] = seqan3::tuple_split<2>(t);
static_assert(std::same_as<decltype(left), std::tuple<int, char>>);
static_assert(std::same_as<decltype(right), std::tuple<float, std::string>>);
// Split at position 0.
auto [left1, right1] = seqan3::tuple_split<0>(t);
static_assert(std::same_as<decltype(left1), std::tuple<>>);
static_assert(std::same_as<decltype(right1), std::tuple<int, char, float, std::string>>);
// Split at position 4.
auto [left2, right2] = seqan3::tuple_split<4>(t);
static_assert(std::same_as<decltype(left2), std::tuple<int, char, float, std::string>>);
static_assert(std::same_as<decltype(right2), std::tuple<>>);
}
seqan3::tuple_split
constexpr auto tuple_split(tuple_t< ts... > const &t)
Splits a tuple like data structure at the given position.
Definition split.hpp:87
split.hpp
Provides seqan3::tuple_split.
string
std::tuple

### Complexity

Linear in the number of elements.

### Thread safety

Concurrent invocations of this functions are thread safe.

## tuple_split() [2/2]

template<size_t pivot_c, template< typename... > typename tuple_t, typename... ts>
requires tuple_like<tuple_t<ts...>>

auto seqan3::tuple_split | ( | tuple_t< ts... > const & | t | ) |

constexpr

Splits a tuple like data structure at the given position.

Template Parameters

  pivot_c | A template value specifying the split position.
  tuple_t | A template alias for a tuple like object.
  ...ts | Types tuple_t is specified with.

Parameters

  [in] | t | The original tuple to split.

Returns
  A new tuple of tuples with the left side of the split and the right side of the split.

Splits a tuple into two tuples, while the element at the split position will be contained in the second tuple. Note, that the returned tuples can be empty. For this reason it is not possible to use tuple like objects, that cannot be empty, i.e. std::pair. Using such an object will emit an compiler error.

### example

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <string>
#include <seqan3/utility/tuple/split.hpp>
int main()
{
// Split at position 2.
std::tuple<int, char, float, std::string> t{1, 'c', 0.3, "hello"};
auto [left, right] = seqan3::tuple_split<2>(t);
static_assert(std::same_as<decltype(left), std::tuple<int, char>>);
static_assert(std::same_as<decltype(right), std::tuple<float, std::string>>);
// Split at position 0.
auto [left1, right1] = seqan3::tuple_split<0>(t);
static_assert(std::same_as<decltype(left1), std::tuple<>>);
static_assert(std::same_as<decltype(right1), std::tuple<int, char, float, std::string>>);
// Split at position 4.
auto [left2, right2] = seqan3::tuple_split<4>(t);
static_assert(std::same_as<decltype(left2), std::tuple<int, char, float, std::string>>);
static_assert(std::same_as<decltype(right2), std::tuple<>>);
}

### Complexity

Linear in the number of elements.

### Thread safety

Concurrent invocations of this functions are thread safe.

Hide me