SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
type_list/traits.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <type_traits>
13
16
17// ----------------------------------------------------------------------------
18// seqan3::list_traits::detail
19// ----------------------------------------------------------------------------
20
21namespace seqan3::list_traits::detail
22{
23
29template <ptrdiff_t idx, typename... pack_t>
31
36template <typename... pack_t>
38
43template <typename... pack_t>
45
51template <typename... pack1_t, typename... pack2_t>
53
60template <typename... pack1_t, typename... pack2_t, typename... more_lists_t>
62{
63 return concat(type_list<pack1_t..., pack2_t...>{}, more_lists_t{}...);
64}
65
70template <typename... pack_t>
72
78template <template <typename> typename trait_t, typename... pack_t>
80
86template <ptrdiff_t idx, typename... pack1_t>
88
94template <size_t count, typename t>
95auto repeat()
96{
97 if constexpr (count == 0)
98 return type_list<>{};
99 else if constexpr (count == 1)
100 return type_list<t>{};
101 else if constexpr (count == 2)
102 return type_list<t, t>{};
103 else if constexpr (count == 3)
104 return type_list<t, t, t>{};
105 else if constexpr (count == 4)
106 return type_list<t, t, t, t>{};
107 else if constexpr (count == 5)
109 else
111}
112
119template <typename replace_t, ptrdiff_t idx, typename... pack_t>
121
123inline constexpr type_list<> reverse(type_list<>)
124{
125 return {};
126}
127
129template <typename head_t, typename... pack_t>
131{
132 return concat(reverse(type_list<pack_t...>{}), type_list<head_t>{});
133}
134
136template <typename... current_list_t>
139{
140 return {};
141}
142
144template <typename... current_list_t, typename remove_t, typename... remove_list_t>
146{
147 constexpr auto pos = seqan3::pack_traits::find<remove_t, current_list_t...>;
148 if constexpr (pos >= 0)
149 {
150 using split_list_t = seqan3::pack_traits::split_after<pos, current_list_t...>;
151
152 using split_list1_t = typename split_list_t::first_type;
153 using split_list2_t = decltype(drop_front(typename split_list_t::second_type{}));
154 using filtered_list_t = decltype(concat(split_list1_t{}, split_list2_t{}));
155 return type_list_difference(filtered_list_t{}, seqan3::type_list<remove_t, remove_list_t...>{});
156 }
157 else
158 {
159 // remove_t not contained in current_list_t
160 using filtered_list_t = seqan3::type_list<current_list_t...>;
161 return type_list_difference(filtered_list_t{}, seqan3::type_list<remove_list_t...>{});
162 }
163}
164
165} // namespace seqan3::list_traits::detail
166
167// ----------------------------------------------------------------------------
168// seqan3::list_traits
169// ----------------------------------------------------------------------------
170
172namespace seqan3::list_traits
173{
174
180template <typename list_t>
182inline constexpr size_t size = 0;
184
191template <typename... pack_t>
192inline constexpr size_t size<type_list<pack_t...>> = sizeof...(pack_t);
193
195template <typename query_t, typename list_t>
197inline constexpr ptrdiff_t count = -1;
199
206template <typename query_t, typename... pack_t>
207inline constexpr ptrdiff_t count<query_t, type_list<pack_t...>> = seqan3::pack_traits::count<query_t, pack_t...>;
208
210template <typename query_t, typename list_t>
212inline constexpr ptrdiff_t find = -1;
214
221template <typename query_t, typename... pack_t>
222inline constexpr ptrdiff_t find<query_t, type_list<pack_t...>> =
223 seqan3::pack_traits::detail::find<query_t, pack_t...>();
224
226template <template <typename> typename pred_t, typename list_t>
228inline constexpr ptrdiff_t find_if = -1;
230
237template <template <typename> typename pred_t, typename... pack_t>
238inline constexpr ptrdiff_t find_if<pred_t, type_list<pack_t...>> =
239 seqan3::pack_traits::detail::find_if<pred_t, pack_t...>();
240
247template <typename query_t, typename list_t>
249inline constexpr bool contains = (find<query_t, list_t> != -1);
250
252
273template <ptrdiff_t idx, typename list_t>
275 && ((idx >= 0 && idx < size<list_t>) || (-idx <= size<list_t>))
276using at = typename decltype(detail::at<idx>(list_t{}))::type;
277
291template <typename list_t>
293using front = typename decltype(detail::front(list_t{}))::type;
294
311template <typename list_t>
313using back = typename decltype(detail::back(list_t{}))::type;
314
316
337template <typename... lists_t>
339using concat = decltype(detail::concat(lists_t{}...));
340
354template <typename list_t>
356using drop_front = decltype(detail::drop_front(list_t{}));
357
372template <ptrdiff_t i, typename list_t>
373 requires (seqan3::detail::template_specialisation_of<list_t, seqan3::type_list>) && (i >= 0 && i <= size<list_t>)
374using take = typename decltype(detail::split_after<i>(list_t{}))::first_type;
375
390template <ptrdiff_t i, typename list_t>
391 requires (seqan3::detail::template_specialisation_of<list_t, seqan3::type_list>) && (i >= 0 && i <= size<list_t>)
392using drop = typename decltype(detail::split_after<i>(list_t{}))::second_type;
393
408template <ptrdiff_t i, typename list_t>
409 requires (seqan3::detail::template_specialisation_of<list_t, seqan3::type_list>) && (i >= 0 && i <= size<list_t>)
410using take_last = drop<size<list_t> - i, list_t>;
411
426template <ptrdiff_t i, typename list_t>
427 requires (seqan3::detail::template_specialisation_of<list_t, seqan3::type_list>) && (i >= 0 && i <= size<list_t>)
428using drop_last = take<size<list_t> - i, list_t>;
429
444template <ptrdiff_t i, typename list_t>
445 requires (seqan3::detail::template_specialisation_of<list_t, seqan3::type_list>) && (i >= 0 && i <= size<list_t>)
446using split_after = decltype(detail::split_after<i>(list_t{}));
447
465template <template <typename> typename trait_t, typename list_t>
467using transform = decltype(detail::transform<trait_t>(list_t{}));
468
484template <typename replace_t, std::ptrdiff_t i, typename list_t>
485 requires (seqan3::detail::template_specialisation_of<list_t, seqan3::type_list>) && (i >= 0 && i < size<list_t>)
486using replace_at = decltype(detail::replace_at<replace_t, i>(list_t{}));
487
500template <size_t count, typename t>
501using repeat = decltype(detail::repeat<count, t>());
503
504} // namespace seqan3::list_traits
decltype(detail::split_after< i >(list_t{})) split_after
Split a seqan3::type_list into two parts returned as a pair of seqan3::type_list.
Definition type_list/traits.hpp:446
typename decltype(detail::split_after< i >(list_t{}))::first_type take
Return a seqan3::type_list of the first n types in the input type list.
Definition type_list/traits.hpp:374
std::type_identity< seqan3::pack_traits::front< pack_t... > > front(type_list< pack_t... >)
Implementation for seqan3::list_traits::front.
decltype(detail::concat(lists_t{}...)) concat
Join two seqan3::type_list s into one.
Definition type_list/traits.hpp:339
constexpr bool contains
Whether a type occurs in a type list or not.
Definition type_list/traits.hpp:249
drop< size< list_t > - i, list_t > take_last
Return a seqan3::type_list of the last n types in the input type list.
Definition type_list/traits.hpp:410
typename decltype(detail::front(list_t{}))::type front
Return the first type from the type list.
Definition type_list/traits.hpp:293
pack_traits::drop_front< pack_t... > drop_front(type_list< pack_t... >)
Implementation for seqan3::list_traits::drop_front.
take< size< list_t > - i, list_t > drop_last
Return a seqan3::type_list of the types the input type list, except the last n.
Definition type_list/traits.hpp:428
auto repeat()
Implementation for seqan3::list_traits::repeat.
Definition type_list/traits.hpp:95
decltype(detail::replace_at< replace_t, i >(list_t{})) replace_at
Replace the type at the given index with the given type.
Definition type_list/traits.hpp:486
pack_traits::transform< trait_t, pack_t... > transform(type_list< pack_t... >)
Implementation for seqan3::list_traits::transform.
decltype(detail::repeat< count, t >()) repeat
Create a type list with the given type repeated count times..
Definition type_list/traits.hpp:501
std::type_identity< seqan3::pack_traits::back< pack_t... > > back(type_list< pack_t... >)
Implementation for seqan3::list_traits::back.
typename decltype(detail::split_after< i >(list_t{}))::second_type drop
Return a seqan3::type_list of the types in the input type list, except the first n.
Definition type_list/traits.hpp:392
typename decltype(detail::at< idx >(list_t{}))::type at
Return the type at given index from the type list.
Definition type_list/traits.hpp:276
std::type_identity< seqan3::pack_traits::at< idx, pack_t... > > at(type_list< pack_t... >)
Implementation for seqan3::list_traits::at.
decltype(detail::transform< trait_t >(list_t{})) transform
Apply a transformation trait to every type in the list and return a seqan3::type_list of the results.
Definition type_list/traits.hpp:467
type_list< pack1_t..., pack2_t... > concat(type_list< pack1_t... >, type_list< pack2_t... >)
Implementation for seqan3::list_traits::concat.
typename decltype(detail::back(list_t{}))::type back
Return the last type from the type list.
Definition type_list/traits.hpp:313
decltype(detail::drop_front(list_t{})) drop_front
Return a seqan3::type_list of all the types in the type list, except the first.
Definition type_list/traits.hpp:356
decltype(detail::replace_at< replace_t, i, pack_t... >(std::make_index_sequence< size< pack_t... > >{})) replace_at
Replace the type at the given index with the given type.
Definition type_pack/traits.hpp:440
typename decltype(detail::drop_front< pack_t... >())::type drop_front
Return a seqan3::type_list of all the types in the type pack, except the first.
Definition type_pack/traits.hpp:305
typename decltype((std::type_identity< pack_t >{},...))::type back
Return the last type from the type pack.
Definition type_pack/traits.hpp:282
constexpr ptrdiff_t find
Get the index of the first occurrence of a type in a pack.
Definition type_pack/traits.hpp:179
constexpr ptrdiff_t count
Count the occurrences of a type in a pack.
Definition type_pack/traits.hpp:161
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
constexpr ptrdiff_t find_if()
Implementation for seqan3::pack_traits::find_if.
Definition type_pack/traits.hpp:44
constexpr ptrdiff_t find()
Implementation for seqan3::pack_traits::find.
Definition type_pack/traits.hpp:31
decltype(detail::split_after< i, pack_t... >(type_list<>{})) split_after
Split a type pack into two parts returned as a pair of seqan3::type_list.
Definition type_pack/traits.hpp:421
typename decltype(detail::front< pack_t... >())::type front
Return the first type from the type pack.
Definition type_pack/traits.hpp:262
Provides concept seqan3::template_specialisation_of<mytype, [...]> for checking the type specialisati...
Namespace containing traits for working on seqan3::type_list.
Type that contains multiple types.
Definition type_list.hpp:26
constexpr seqan3::type_list< current_list_t... > type_list_difference(seqan3::type_list< current_list_t... >, seqan3::type_list<>)
Constructs the multiset difference list1 \ list2 [recursion anchor].
Definition type_list/traits.hpp:137
Provides seqan3::type_list.
Provides various traits for template packs.
Hide me