SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
detail/record.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
12#pragma once
13
14#include <ranges>
15
16#include <seqan3/io/record.hpp>
20
21namespace seqan3::detail
22{
23
24// ----------------------------------------------------------------------------
25// Fields
26// ----------------------------------------------------------------------------
27
31template <typename t>
32concept fields_specialisation = is_value_specialisation_of_v<t, fields>;
33
34// ----------------------------------------------------------------------------
35// select_types_with_ids
36// ----------------------------------------------------------------------------
37
58template <typename field_types,
59 typename field_types_as_ids,
60 typename selected_field_ids,
61 size_t field_no = 0,
62 typename... return_types>
63struct select_types_with_ids // unconstrained template is recursion anchor
64{
66 using type = type_list<return_types...>;
67};
68
72template <typename field_types,
73 typename field_types_as_ids,
74 typename selected_field_ids,
75 size_t field_no = 0,
76 typename... return_types>
78 typename select_types_with_ids<field_types, field_types_as_ids, selected_field_ids, field_no, return_types...>::
79 type;
81template <typename field_types,
82 typename field_types_as_ids,
83 typename selected_field_ids,
84 size_t field_no,
85 typename... return_types>
86 requires (field_no < selected_field_ids::as_array.size()) // perform recursion while not at end
88{
89 static_assert(field_types_as_ids::contains(selected_field_ids::as_array[field_no]),
90 "You selected a field that was not in field_types_as_ids.");
91
92 // call this type trait again, but increase index by one and append a type to the returned type list.
94 field_types,
95 field_types_as_ids,
96 selected_field_ids,
97 field_no + 1,
98 return_types...,
99 list_traits::at<field_types_as_ids::index_of(selected_field_ids::as_array[field_no]), field_types>>;
100};
102
103// ----------------------------------------------------------------------------
104// get_or_ignore
105// ----------------------------------------------------------------------------
106
109template <field f, typename field_types, typename field_ids>
111{
112 if constexpr (field_ids::contains(f))
113 return std::get<field_ids::index_of(f)>(r);
114 else
115 return std::ignore;
116}
117
119template <field f, typename field_types, typename field_ids>
121{
122 if constexpr (field_ids::contains(f))
123 return std::get<field_ids::index_of(f)>(r);
124 else
125 return std::ignore;
126}
127
129template <size_t i, tuple_like tuple_t>
130auto & get_or_ignore(tuple_t & t)
131{
132 if constexpr (i < std::tuple_size_v<tuple_t>)
133 return std::get<i>(t);
134 else
135 return std::ignore;
136}
137
139template <size_t i, tuple_like tuple_t>
140auto const & get_or_ignore(tuple_t const & t)
141{
142 if constexpr (i < std::tuple_size_v<tuple_t>)
143 return std::get<i>(t);
144 else
145 return std::ignore;
146}
147
148// ----------------------------------------------------------------------------
149// get_or
150// ----------------------------------------------------------------------------
151
154template <field f, typename field_types, typename field_ids, typename or_type>
155decltype(auto) get_or(record<field_types, field_ids> & r, or_type && or_value)
156{
157 if constexpr (field_ids::contains(f))
158 return std::get<field_ids::index_of(f)>(r);
159 else
160 return std::forward<or_type>(or_value);
161}
162
164template <field f, typename field_types, typename field_ids, typename or_type>
165decltype(auto) get_or(record<field_types, field_ids> const & r, or_type && or_value)
166{
167 if constexpr (field_ids::contains(f))
168 return std::get<field_ids::index_of(f)>(r);
169 else
170 return std::forward<or_type>(or_value);
171}
172
174template <size_t i, typename or_type, typename... types>
175decltype(auto) get_or(std::tuple<types...> & t, or_type && or_value)
176{
177 if constexpr (i < sizeof...(types))
178 return std::get<i>(t);
179 else
180 return std::forward<or_type>(or_value);
181}
182
184template <size_t i, typename or_type, typename... types>
185decltype(auto) get_or(std::tuple<types...> const & t, or_type && or_value)
186{
187 if constexpr (i < sizeof...(types))
188 return std::get<i>(t);
189 else
190 return std::forward<or_type>(or_value);
191}
192
193// ----------------------------------------------------------------------------
194// range_wrap_ignore
195// ----------------------------------------------------------------------------
196
199template <std::ranges::input_range rng_t>
200inline auto & range_wrap_ignore(rng_t & range)
201{
202 return range;
203}
204
212inline auto range_wrap_ignore(ignore_t const &)
213{
214 return views::repeat(std::ignore);
215}
216
217} // namespace seqan3::detail
Auxiliary concept that checks whether a type is a specialisation of seqan3::fields.
Definition detail/record.hpp:32
auto & get_or_ignore(record< field_types, field_ids > &r)
Access an element in a std::tuple or seqan3::record; return reference to std::ignore if not contained...
Definition detail/record.hpp:110
decltype(auto) get_or(record< field_types, field_ids > &r, or_type &&or_value)
Access an element in a std::tuple or seqan3::record; return or_value if not contained.
Definition detail/record.hpp:155
auto & range_wrap_ignore(rng_t &range)
Pass through the reference to the argument in case the argument satisfies std::ranges::input_range.
Definition detail/record.hpp:200
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
constexpr detail::repeat_fn repeat
A view factory that repeats a given value infinitely.
Definition repeat.hpp:344
The internal SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
Provides the seqan3::record template and the seqan3::field enum.
Provides the seqan3::views::repeat.
Exposes a subset of types as a seqan3::type_list selected based on their IDs.
Definition detail/record.hpp:64
typename select_types_with_ids< field_types, field_types_as_ids, selected_field_ids, field_no, return_types... >::type select_types_with_ids_t
Shortcut for seqan3::select_types_with_ids (transformation_trait shortcut).
Definition detail/record.hpp:79
The class template that file records are based on; behaves like a std::tuple.
Definition record.hpp:190
Type that contains multiple types.
Definition type_list.hpp:26
Provides traits for seqan3::type_list.
Provides seqan3::tuple_like.
Hide me