BioC++ core-0.7.0
The Modern C++ libraries for Bioinformatics.
 
Loading...
Searching...
No Matches
tuple_utility.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2022 deCODE Genetics
3// Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
4// Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik
5// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
6// shipped with this file and also available at: https://github.com/biocpp/biocpp-core/blob/main/LICENSE.md
7// -----------------------------------------------------------------------------------------------------
8
14#pragma once
15
16#include <utility>
17
21
22namespace bio::meta::detail
23{
24
38template <size_t beg, template <typename...> typename tuple_t, size_t... Is, typename... ts>
39 requires(tuple_like<tuple_t<ts...>> && tuple_like<tuple_t<>>)
40constexpr auto tuple_split(tuple_t<ts...> const & t, std::index_sequence<Is...> const & BIOCPP_DOXYGEN_ONLY(idx))
41{
42 return tuple_t<std::tuple_element_t<beg + Is, tuple_t<ts...>>...>{std::get<beg + Is>(t)...};
43}
44
46template <size_t beg, template <typename...> typename tuple_t, size_t... Is, typename... ts>
47 requires(tuple_like<tuple_t<ts...>> && tuple_like<tuple_t<>>)
48constexpr auto tuple_split(tuple_t<ts...> && t, std::index_sequence<Is...> const & BIOCPP_DOXYGEN_ONLY(idx))
49{
50 return tuple_t<std::tuple_element_t<beg + Is, tuple_t<ts...>>...>{std::move(std::get<beg + Is>(t))...};
51}
52} // namespace bio::meta::detail
53
54namespace bio::meta
55{
88template <size_t pivot_c, template <typename...> typename tuple_t, typename... ts>
89 requires tuple_like<tuple_t<ts...>>
90constexpr auto tuple_split(tuple_t<ts...> const & t)
91{
92 static_assert(pivot_c <= sizeof...(ts));
93
94 return tuple_t{detail::tuple_split<0>(t, std::make_index_sequence<pivot_c>{}),
95 detail::tuple_split<pivot_c>(t, std::make_index_sequence<sizeof...(ts) - pivot_c>{})};
96}
97
99template <size_t pivot_c, template <typename...> typename tuple_t, typename... ts>
100 requires tuple_like<tuple_t<ts...>>
101constexpr auto tuple_split(tuple_t<ts...> && t)
102{
103 static_assert(pivot_c <= sizeof...(ts));
104
105 //NOLINTBEGIN(bugprone-use-after-move)
106 return tuple_t{detail::tuple_split<0>(std::move(t), std::make_index_sequence<pivot_c>{}),
107 detail::tuple_split<pivot_c>(std::move(t), std::make_index_sequence<sizeof...(ts) - pivot_c>{})};
108 //NOLINTEND(bugprone-use-after-move)
109}
110
137template <typename pivot_t, tuple_like tuple_t>
138constexpr auto tuple_split(tuple_t && t)
139{
140 constexpr size_t pivot_c = list_traits::find<pivot_t, detail::tuple_type_list_t<std::remove_cvref_t<tuple_t>>>;
141
142 static_assert(pivot_c <= std::tuple_size_v<std::remove_cvref_t<tuple_t>>);
143
144 return tuple_split<pivot_c>(std::forward<tuple_t>(t));
145}
146
167template <tuple_like tuple_t>
168constexpr auto tuple_pop_front(tuple_t && t)
169{
170 static_assert(std::tuple_size_v<std::remove_cvref_t<tuple_t>> > 0);
171
172 return std::get<1>(tuple_split<1>(std::forward<tuple_t>(t)));
173}
175
176} // namespace bio::meta
constexpr auto tuple_split(tuple_t< ts... > const &t)
Splits a tuple like data structure at the given position.
Definition: tuple_utility.hpp:90
constexpr auto tuple_pop_front(tuple_t &&t)
Removes the first element of a tuple.
Definition: tuple_utility.hpp:168
The Meta module's namespace.
Provides bio::meta::pod_tuple.
Provides traits for meta::type_list.
Provides bio::meta::tuple_like.