BioC++ core-0.7.0
The Modern C++ libraries for Bioinformatics.
 
Loading...
Searching...
No Matches
pod_tuple.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 <tuple>
17#include <type_traits>
18
20
21namespace bio::meta
22{
23
25template <typename... types>
27{};
28
49template <typename type0, typename... types>
50struct pod_tuple<type0, types...>
51{
54 type0 _head;
56 pod_tuple<types...> _tail;
58
64 friend bool operator==(pod_tuple const & lhs, pod_tuple const & rhs) noexcept = default;
65
67 constexpr friend auto operator<=>(pod_tuple const & lhs, pod_tuple const & rhs) noexcept
68 {
69 return std::tie(lhs._head, lhs._tail) <=> std::tie(rhs._head, rhs._tail);
70 }
72};
73
78template <typename type0>
79struct pod_tuple<type0>
80{
83 type0 _head;
85
91 friend bool operator==(pod_tuple const & lhs, pod_tuple const & rhs) noexcept = default;
92
94 constexpr friend auto operator<=>(pod_tuple const & lhs, pod_tuple const & rhs) noexcept = default;
96};
97
100template <typename... types>
101pod_tuple(types &&...) -> pod_tuple<types...>;
102
111template <std::size_t i, typename... types>
112constexpr auto & get(bio::meta::pod_tuple<types...> & t) noexcept
113 requires(i < sizeof...(types))
114{
115 if constexpr (i == 0)
116 return t._head;
117 else
118 return bio::meta::get<i - 1>(t._tail);
119}
120
123template <std::size_t i, typename... types>
124constexpr auto const & get(bio::meta::pod_tuple<types...> const & t) noexcept
125 requires(i < sizeof...(types))
126{
127 if constexpr (i == 0)
128 return t._head;
129 else
130 return bio::meta::get<i - 1>(t._tail);
131}
132
133// extra overloads for temporaries required, because members of temporaries may only be returned as temporaries
136template <std::size_t i, typename... types>
137constexpr auto && get(bio::meta::pod_tuple<types...> && t) noexcept
138 requires(i < sizeof...(types))
139{
140 if constexpr (i == 0)
141 return std::move(t._head);
142 else
143 return bio::meta::get<i - 1>(std::move(t._tail));
144}
145
148template <std::size_t i, typename... types>
149constexpr auto const && get(bio::meta::pod_tuple<types...> const && t) noexcept
150 requires(i < sizeof...(types))
151{
152 if constexpr (i == 0)
153 return std::move(t._head);
154 else
155 return bio::meta::get<i - 1>(std::move(t._tail));
156}
158
169template <typename type, typename... arg_types>
170constexpr auto & get(bio::meta::pod_tuple<arg_types...> & t) noexcept
171 requires(meta::detail::pack_traits::count<type, arg_types...> == 1)
172{
173 return bio::meta::get<meta::detail::pack_traits::find<type, arg_types...>>(t);
174}
175
178template <typename type, typename... arg_types>
179constexpr auto const & get(bio::meta::pod_tuple<arg_types...> const & t) noexcept
180 requires(meta::detail::pack_traits::count<type, arg_types...> == 1)
181{
182 return bio::meta::get<meta::detail::pack_traits::find<type, arg_types...>>(t);
183}
184
187template <typename type, typename... arg_types>
188constexpr auto && get(bio::meta::pod_tuple<arg_types...> && t) noexcept
189 requires(meta::detail::pack_traits::count<type, arg_types...> == 1)
190{
191 return bio::meta::get<meta::detail::pack_traits::find<type, arg_types...>>(std::move(t));
192}
193
196template <typename type, typename... arg_types>
197constexpr auto const && get(bio::meta::pod_tuple<arg_types...> const && t) noexcept
198 requires(meta::detail::pack_traits::count<type, arg_types...> == 1)
199{
200 return bio::meta::get<meta::detail::pack_traits::find<type, arg_types...>>(std::move(t));
201}
203
204} // namespace bio::meta
205
206namespace std
207{
208
210template <std::size_t i, typename... types>
211constexpr auto & get(bio::meta::pod_tuple<types...> & t) noexcept
212 requires(i < sizeof...(types))
213{
214 return bio::meta::get<i>(t);
215}
216
217template <std::size_t i, typename... types>
218constexpr auto const & get(bio::meta::pod_tuple<types...> const & t) noexcept
219 requires(i < sizeof...(types))
220{
221 return bio::meta::get<i>(t);
222}
223
224template <std::size_t i, typename... types>
225constexpr auto && get(bio::meta::pod_tuple<types...> && t) noexcept
226 requires(i < sizeof...(types))
227{
228 return bio::meta::get<i>(std::move(t));
229}
230
231template <std::size_t i, typename... types>
232constexpr auto const && get(bio::meta::pod_tuple<types...> const && t) noexcept
233 requires(i < sizeof...(types))
234{
235 return bio::meta::get<i>(std::move(t));
236}
237
238template <typename type, typename... types>
239constexpr auto & get(bio::meta::pod_tuple<types...> & t) noexcept
240 requires(bio::meta::detail::pack_traits::count<type, types...> == 1)
241{
242 return bio::meta::get<type>(t);
243}
244
245template <typename type, typename... types>
246constexpr auto const & get(bio::meta::pod_tuple<types...> const & t) noexcept
247 requires(bio::meta::detail::pack_traits::count<type, types...> == 1)
248{
249 return bio::meta::get<type>(t);
250}
251
252template <typename type, typename... types>
253constexpr auto && get(bio::meta::pod_tuple<types...> && t) noexcept
254 requires(bio::meta::detail::pack_traits::count<type, types...> == 1)
255{
256 return bio::meta::get<type>(std::move(t));
257}
258
259template <typename type, typename... types>
260constexpr auto const && get(bio::meta::pod_tuple<types...> const && t) noexcept
261 requires(bio::meta::detail::pack_traits::count<type, types...> == 1)
262{
263 return bio::meta::get<type>(std::move(t));
264}
266
272template <std::size_t i, template <typename...> typename t, typename... types>
273 requires(i < sizeof...(types)) && std::is_base_of_v<bio::meta::pod_tuple<types...>, t<types...>>
274struct tuple_element<i, t<types...>>
275{
277 using type = bio::meta::detail::pack_traits::at<i, types...>;
278};
279
285template <template <typename...> typename t, typename... types>
286 requires std::is_base_of_v<bio::meta::pod_tuple<types...>, t<types...>>
287struct tuple_size<t<types...>> : public std::integral_constant<std::size_t, sizeof...(types)>
288{};
289
290} // namespace std
T is_base_of_v
The Meta module's namespace.
friend bool operator==(pod_tuple const &lhs, pod_tuple const &rhs) noexcept=default
Checks whether *this is equal to rhs.
constexpr friend auto operator<=>(pod_tuple const &lhs, pod_tuple const &rhs) noexcept
Checks whether *this is equal to rhs.
Definition: pod_tuple.hpp:67
friend bool operator==(pod_tuple const &lhs, pod_tuple const &rhs) noexcept=default
Checks whether *this is equal to rhs.
constexpr friend auto operator<=>(pod_tuple const &lhs, pod_tuple const &rhs) noexcept=default
Checks whether *this is equal to rhs.
Behaves like std::tuple but is an aggregate PODType.
Definition: pod_tuple.hpp:27
constexpr auto && get(bio::meta::pod_tuple< types... > &&t) noexcept
The same as std::get on an std::tuple.
Definition: pod_tuple.hpp:137
constexpr auto const && get(bio::meta::pod_tuple< types... > const &&t) noexcept
The same as std::get on an std::tuple.
Definition: pod_tuple.hpp:149
constexpr auto const & get(bio::meta::pod_tuple< arg_types... > const &t) noexcept
The same as std::get on an std::tuple.
Definition: pod_tuple.hpp:179
constexpr auto && get(bio::meta::pod_tuple< arg_types... > &&t) noexcept
The same as std::get on an std::tuple.
Definition: pod_tuple.hpp:188
constexpr auto & get(bio::meta::pod_tuple< arg_types... > &t) noexcept
The same as std::get on an std::tuple.
Definition: pod_tuple.hpp:170
pod_tuple(types &&...) -> pod_tuple< types... >
User defined deduction guide enables easy use.
constexpr auto const & get(bio::meta::pod_tuple< types... > const &t) noexcept
The same as std::get on an std::tuple.
Definition: pod_tuple.hpp:124
constexpr auto & get(bio::meta::pod_tuple< types... > &t) noexcept
The same as std::get on an std::tuple.
Definition: pod_tuple.hpp:112
constexpr auto const && get(bio::meta::pod_tuple< arg_types... > const &&t) noexcept
The same as std::get on an std::tuple.
Definition: pod_tuple.hpp:197
bio::meta::detail::pack_traits::at< i, types... > type
Element type.
Definition: pod_tuple.hpp:277
T tie(T... args)
Provides traits for meta::type_list.