SeqAn3 3.1.0-rc.2
The Modern C++ library for sequence analysis.
pack_algorithm.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2021, Knut Reinert & MPI für molekulare Genetik
4// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5// shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6// -----------------------------------------------------------------------------------------------------
7
13#pragma once
14
15#include <seqan3/std/concepts>
17#include <utility>
18
20
21namespace seqan3::detail
22{
23
25template <typename type_list_t>
26struct type_list_expander;
28
49template <template <typename ...> typename type_list_t, typename ...args_t>
50struct type_list_expander<type_list_t<args_t...>>
51{
62 template <typename fn_t>
64 requires std::invocable<fn_t, std::type_identity<args_t>...>
66 static constexpr std::invoke_result_t<fn_t, std::type_identity<args_t>...> invoke_on_type_identities(fn_t && fn)
67 {
68 return fn(std::type_identity<args_t>{}...);
69 }
70};
71
72//-----------------------------------------------------------------------------
73// all_of
74//-----------------------------------------------------------------------------
75
106template <typename unary_predicate_t, typename ...pack_t>
108 requires (std::predicate<unary_predicate_t, pack_t> && ...)
110constexpr bool all_of(unary_predicate_t && fn, pack_t && ...args)
111{
112 return (fn(std::forward<pack_t>(args)) && ...);
113}
114
149template <typename type_list_t, typename unary_predicate_t>
150[[nodiscard]] constexpr bool all_of(unary_predicate_t && fn)
152 requires template_specialisation_of<type_list_t, seqan3::type_list>
154{
155 return type_list_expander<type_list_t>::invoke_on_type_identities([&] (auto && ...type_identities)
156 {
157 return all_of(fn, std::forward<decltype(type_identities)>(type_identities)...);
158 });
159}
160
161//-----------------------------------------------------------------------------
162// for_each
163//-----------------------------------------------------------------------------
164
192template <typename unary_function_t, typename ...pack_t>
194 requires (std::invocable<unary_function_t, pack_t> && ...)
196constexpr void for_each(unary_function_t && fn, pack_t && ...args)
197{
198 (fn(std::forward<pack_t>(args)), ...);
199}
200
235template <typename type_list_t, typename unary_function_t>
237 requires template_specialisation_of<type_list_t, seqan3::type_list>
239constexpr void for_each(unary_function_t && fn)
240{
241 type_list_expander<type_list_t>::invoke_on_type_identities([&] (auto && ...type_identities)
242 {
243 for_each(fn, std::forward<decltype(type_identities)>(type_identities)...);
244 });
245}
246
247} // namespace seqan3::detail
T all_of(T... args)
The Concepts library.
T for_each(T... args)
T forward(T... args)
Provides seqan3::type_list.
Provides C++20 additions to the type_traits header.