Loading...
Searching...
No Matches
pod_tuple.hpp
Go to the documentation of this file.
// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: BSD-3-Clause
#pragma once
#include <tuple>
#include <type_traits>
#include <seqan3/utility/concept.hpp>
#include <seqan3/utility/type_pack/traits.hpp>
namespace seqan3
{
#define SEQAN_NOT_POD "If you are not going to insert a POD type, use std::tuple instead."
template <typename... types>
struct pod_tuple
{};
template <typename type0, typename... types>
struct pod_tuple<type0, types...>
{
static_assert(std::is_standard_layout_v<type0> && seqan3::trivial<type0>, SEQAN_NOT_POD);
type0 _head;
pod_tuple<types...> _tail;
constexpr pod_tuple() noexcept = default;
constexpr pod_tuple(pod_tuple const &) noexcept = default;
constexpr pod_tuple & operator=(pod_tuple const &) noexcept = default;
constexpr pod_tuple(pod_tuple &&) noexcept = default;
constexpr pod_tuple & operator=(pod_tuple &&) noexcept = default;
constexpr ~pod_tuple() noexcept = default;
constexpr pod_tuple(type0 v0, types... args) noexcept : _head{v0}, _tail{args...}
{}
constexpr bool operator==(pod_tuple const & rhs) const noexcept
{
return std::tie(_head, _tail) == std::tie(rhs._head, rhs._tail);
}
constexpr bool operator!=(pod_tuple const & rhs) const noexcept
{
return std::tie(_head, _tail) != std::tie(rhs._head, rhs._tail);
}
constexpr bool operator<(pod_tuple const & rhs) const noexcept
{
return std::tie(_head, _tail) < std::tie(rhs._head, rhs._tail);
}
constexpr bool operator>(pod_tuple const & rhs) const noexcept
{
return std::tie(_head, _tail) > std::tie(rhs._head, rhs._tail);
}
constexpr bool operator<=(pod_tuple const & rhs) const noexcept
{
return std::tie(_head, _tail) <= std::tie(rhs._head, rhs._tail);
}
constexpr bool operator>=(pod_tuple const & rhs) const noexcept
{
return std::tie(_head, _tail) >= std::tie(rhs._head, rhs._tail);
}
};
template <typename type0>
struct pod_tuple<type0>
{
static_assert(std::is_standard_layout_v<type0> && seqan3::trivial<type0>, SEQAN_NOT_POD);
type0 _head;
constexpr bool operator==(pod_tuple const & rhs) const noexcept
{
return _head == rhs._head;
}
constexpr bool operator!=(pod_tuple const & rhs) const noexcept
{
return _head != rhs._head;
}
constexpr bool operator<(pod_tuple const & rhs) const noexcept
{
return _head < rhs._head;
}
constexpr bool operator>(pod_tuple const & rhs) const noexcept
{
return _head > rhs._head;
}
constexpr bool operator<=(pod_tuple const & rhs) const noexcept
{
return _head <= rhs._head;
}
constexpr bool operator>=(pod_tuple const & rhs) const noexcept
{
return _head >= rhs._head;
}
};
#undef SEQAN_NOT_POD
template <typename... types>
pod_tuple(types &&...) -> pod_tuple<types...>;
template <std::size_t i, typename... types>
constexpr auto & get(seqan3::pod_tuple<types...> & t) noexcept
requires (i < sizeof...(types))
{
if constexpr (i == 0)
return t._head;
else
return seqan3::get<i - 1>(t._tail);
}
template <std::size_t i, typename... types>
constexpr auto const & get(seqan3::pod_tuple<types...> const & t) noexcept
requires (i < sizeof...(types))
{
if constexpr (i == 0)
return t._head;
else
return seqan3::get<i - 1>(t._tail);
}
// extra overloads for temporaries required, because members of temporaries may only be returned as temporaries
template <std::size_t i, typename... types>
constexpr auto && get(seqan3::pod_tuple<types...> && t) noexcept
requires (i < sizeof...(types))
{
if constexpr (i == 0)
return std::move(t._head);
else
return seqan3::get<i - 1>(std::move(t._tail));
}
template <std::size_t i, typename... types>
constexpr auto const && get(seqan3::pod_tuple<types...> const && t) noexcept
requires (i < sizeof...(types))
{
if constexpr (i == 0)
return std::move(t._head);
else
return seqan3::get<i - 1>(std::move(t._tail));
}
template <typename type, typename... arg_types>
constexpr auto & get(seqan3::pod_tuple<arg_types...> & t) noexcept
requires (seqan3::pack_traits::count<type, arg_types...> == 1)
{
return seqan3::get<seqan3::pack_traits::find<type, arg_types...>>(t);
}
template <typename type, typename... arg_types>
constexpr auto const & get(seqan3::pod_tuple<arg_types...> const & t) noexcept
requires (seqan3::pack_traits::count<type, arg_types...> == 1)
{
return seqan3::get<seqan3::pack_traits::find<type, arg_types...>>(t);
}
template <typename type, typename... arg_types>
constexpr auto && get(seqan3::pod_tuple<arg_types...> && t) noexcept
requires (seqan3::pack_traits::count<type, arg_types...> == 1)
{
return seqan3::get<seqan3::pack_traits::find<type, arg_types...>>(std::move(t));
}
template <typename type, typename... arg_types>
constexpr auto const && get(seqan3::pod_tuple<arg_types...> const && t) noexcept
requires (seqan3::pack_traits::count<type, arg_types...> == 1)
{
return seqan3::get<seqan3::pack_traits::find<type, arg_types...>>(std::move(t));
}
} // namespace seqan3
namespace std
{
template <std::size_t i, typename... types>
constexpr auto & get(seqan3::pod_tuple<types...> & t) noexcept
requires (i < sizeof...(types))
{
return seqan3::get<i>(t);
}
template <std::size_t i, typename... types>
constexpr auto const & get(seqan3::pod_tuple<types...> const & t) noexcept
requires (i < sizeof...(types))
{
return seqan3::get<i>(t);
}
template <std::size_t i, typename... types>
constexpr auto && get(seqan3::pod_tuple<types...> && t) noexcept
requires (i < sizeof...(types))
{
return seqan3::get<i>(std::move(t));
}
template <std::size_t i, typename... types>
constexpr auto const && get(seqan3::pod_tuple<types...> const && t) noexcept
requires (i < sizeof...(types))
{
return seqan3::get<i>(std::move(t));
}
template <typename type, typename... types>
constexpr auto & get(seqan3::pod_tuple<types...> & t) noexcept
requires (seqan3::pack_traits::count<type, types...> == 1)
{
return seqan3::get<type>(t);
}
template <typename type, typename... types>
constexpr auto const & get(seqan3::pod_tuple<types...> const & t) noexcept
requires (seqan3::pack_traits::count<type, types...> == 1)
{
return seqan3::get<type>(t);
}
template <typename type, typename... types>
constexpr auto && get(seqan3::pod_tuple<types...> && t) noexcept
requires (seqan3::pack_traits::count<type, types...> == 1)
{
return seqan3::get<type>(std::move(t));
}
template <typename type, typename... types>
constexpr auto const && get(seqan3::pod_tuple<types...> const && t) noexcept
requires (seqan3::pack_traits::count<type, types...> == 1)
{
return seqan3::get<type>(std::move(t));
}
template <std::size_t i, template <typename...> typename t, typename... types>
requires (i < sizeof...(types)) && std::is_base_of_v<seqan3::pod_tuple<types...>, t<types...>>
struct tuple_element<i, t<types...>>
{
using type = seqan3::pack_traits::at<i, types...>;
};
template <template <typename...> typename t, typename... types>
requires std::is_base_of_v<seqan3::pod_tuple<types...>, t<types...>>
struct tuple_size<t<types...>> : public std::integral_constant<std::size_t, sizeof...(types)>
{};
} // namespace std
seqan3::pack_traits::at
typename decltype(detail::at< idx, pack_t... >())::type at
Return the type at given index from the type pack.
Definition type_pack/traits.hpp:245
seqan3::pack_traits::find
constexpr ptrdiff_t find
Get the index of the first occurrence of a type in a pack.
Definition type_pack/traits.hpp:179
seqan3::pack_traits::count
constexpr ptrdiff_t count
Count the occurrences of a type in a pack.
Definition type_pack/traits.hpp:161
std::integral_constant
std::is_base_of_v
T is_base_of_v
std::is_standard_layout_v
T is_standard_layout_v
seqan3
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
seqan3::get
constexpr auto const & get(configuration< configs_t... > const &config) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition configuration.hpp:412
std
SeqAn specific customisations in the standard namespace.
std::size_t
seqan3::pod_tuple< type0, types... >::operator>=
constexpr bool operator>=(pod_tuple const &rhs) const noexcept
Checks whether *this is greater than or equal to rhs.
Definition pod_tuple.hpp:104
seqan3::pod_tuple< type0, types... >::operator!=
constexpr bool operator!=(pod_tuple const &rhs) const noexcept
Checks whether *this is not equal to rhs.
Definition pod_tuple.hpp:80
seqan3::pod_tuple< type0, types... >::operator<=
constexpr bool operator<=(pod_tuple const &rhs) const noexcept
Checks whether *this is less than or equal to rhs.
Definition pod_tuple.hpp:98
seqan3::pod_tuple< type0, types... >::operator==
constexpr bool operator==(pod_tuple const &rhs) const noexcept
Checks whether *this is equal to rhs.
Definition pod_tuple.hpp:74
seqan3::pod_tuple< type0, types... >::operator<
constexpr bool operator<(pod_tuple const &rhs) const noexcept
Checks whether *this is less than rhs.
Definition pod_tuple.hpp:86
seqan3::pod_tuple< type0, types... >::operator>
constexpr bool operator>(pod_tuple const &rhs) const noexcept
Checks whether *this is greater than rhs.
Definition pod_tuple.hpp:92
seqan3::pod_tuple< type0 >::operator<=
constexpr bool operator<=(pod_tuple const &rhs) const noexcept
Checks whether *this is less than or equal to rhs.
Definition pod_tuple.hpp:154
seqan3::pod_tuple< type0 >::operator>
constexpr bool operator>(pod_tuple const &rhs) const noexcept
Checks whether *this is greater than rhs.
Definition pod_tuple.hpp:148
seqan3::pod_tuple< type0 >::operator>=
constexpr bool operator>=(pod_tuple const &rhs) const noexcept
Checks whether *this is greater than or equal to rhs.
Definition pod_tuple.hpp:160
seqan3::pod_tuple< type0 >::operator!=
constexpr bool operator!=(pod_tuple const &rhs) const noexcept
Checks whether *this is not equal to rhs.
Definition pod_tuple.hpp:136
seqan3::pod_tuple< type0 >::operator==
constexpr bool operator==(pod_tuple const &rhs) const noexcept
Checks whether *this is equal to rhs.
Definition pod_tuple.hpp:130
seqan3::pod_tuple< type0 >::operator<
constexpr bool operator<(pod_tuple const &rhs) const noexcept
Checks whether *this is less than rhs.
Definition pod_tuple.hpp:142
seqan3::pod_tuple
Definition pod_tuple.hpp:27
seqan3::pod_tuple::get
constexpr auto && get(seqan3::pod_tuple< types... > &&t) noexcept
The same as std::get on a std::tuple.
Definition pod_tuple.hpp:208
seqan3::pod_tuple::get
constexpr auto & get(seqan3::pod_tuple< arg_types... > &t) noexcept
The same as std::get on a std::tuple.
Definition pod_tuple.hpp:241
seqan3::pod_tuple::get
constexpr auto const & get(seqan3::pod_tuple< types... > const &t) noexcept
The same as std::get on a std::tuple.
Definition pod_tuple.hpp:195
seqan3::pod_tuple::get
constexpr auto & get(seqan3::pod_tuple< types... > &t) noexcept
The same as std::get on a std::tuple.
Definition pod_tuple.hpp:183
seqan3::pod_tuple::get
constexpr auto const && get(seqan3::pod_tuple< types... > const &&t) noexcept
The same as std::get on a std::tuple.
Definition pod_tuple.hpp:220
seqan3::pod_tuple::get
constexpr auto const && get(seqan3::pod_tuple< arg_types... > const &&t) noexcept
The same as std::get on a std::tuple.
Definition pod_tuple.hpp:268
seqan3::pod_tuple::get
constexpr auto && get(seqan3::pod_tuple< arg_types... > &&t) noexcept
The same as std::get on a std::tuple.
Definition pod_tuple.hpp:259
seqan3::pod_tuple::pod_tuple
pod_tuple(types &&...) -> pod_tuple< types... >
User defined deduction guide enables easy use.
seqan3::pod_tuple::get
constexpr auto const & get(seqan3::pod_tuple< arg_types... > const &t) noexcept
The same as std::get on a std::tuple.
Definition pod_tuple.hpp:250
std::tuple_element< i, t< types... > >::type
seqan3::pack_traits::at< i, types... > type
Element type.
Definition pod_tuple.hpp:348
std::tie
T tie(T... args)
tuple
traits.hpp
Provides various traits for template packs.
type_traits
concept.hpp
Provides concepts that do not have equivalents in C++20.
Hide me