SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
pack_algorithm.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2020, 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 <utility>
16 
18 #include <seqan3/std/concepts>
19 #include <seqan3/std/type_traits>
20 
21 namespace seqan3::detail
22 {
23 
25 template <typename type_list_t>
26 struct type_list_expander;
28 
48 template <template <typename ...> typename type_list_t, typename ...args_t>
49 struct type_list_expander<type_list_t<args_t...>>
50 {
61  template <typename fn_t>
63  requires std::invocable<fn_t, std::type_identity<args_t>...>
65  static constexpr std::invoke_result_t<fn_t, std::type_identity<args_t>...> invoke_on_type_identities(fn_t && fn)
66  {
67  return fn(std::type_identity<args_t>{}...);
68  }
69 };
70 
71 //-----------------------------------------------------------------------------
72 // all_of
73 //-----------------------------------------------------------------------------
74 
105 template <typename unary_predicate_t, typename ...pack_t>
107  requires (std::predicate<unary_predicate_t, pack_t> && ...)
109 constexpr bool all_of(unary_predicate_t && fn, pack_t && ...args)
110 {
111  return (fn(std::forward<pack_t>(args)) && ...);
112 }
113 
148 template <typename type_list_t, typename unary_predicate_t>
149 [[nodiscard]] constexpr bool all_of(unary_predicate_t && fn)
151  requires type_list_specialisation<type_list_t>
153 {
154  return type_list_expander<type_list_t>::invoke_on_type_identities([&] (auto && ...type_identities)
155  {
156  return all_of(fn, std::forward<decltype(type_identities)>(type_identities)...);
157  });
158 }
159 
160 //-----------------------------------------------------------------------------
161 // for_each
162 //-----------------------------------------------------------------------------
163 
191 template <typename unary_function_t, typename ...pack_t>
193  requires (std::invocable<unary_function_t, pack_t> && ...)
195 constexpr void for_each(unary_function_t && fn, pack_t && ...args)
196 {
197  (fn(std::forward<pack_t>(args)), ...);
198 }
199 
234 template <typename type_list_t, typename unary_function_t>
236  requires type_list_specialisation<type_list_t>
238 constexpr void for_each(unary_function_t && fn)
239 {
240  type_list_expander<type_list_t>::invoke_on_type_identities([&] (auto && ...type_identities)
241  {
242  for_each(fn, std::forward<decltype(type_identities)>(type_identities)...);
243  });
244 }
245 
246 } // namespace seqan3::detail
std::for_each
T for_each(T... args)
type_traits
Provides C++20 additions to the type_traits header.
utility
std::all_of
T all_of(T... args)
concepts
The Concepts library.
std::forward
T forward(T... args)
std::type_identity
The identity transformation (a transformation_trait that returns the input).
std::invoke_result_t
type_list.hpp
Provides seqan3::type_list.