SeqAn3  3.0.1
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 
19 #include <seqan3/std/concepts>
20 #include <seqan3/std/type_traits>
21 
22 namespace seqan3::detail
23 {
24 
26 template <typename type_list_t>
27 struct type_list_expander;
29 
49 template <template <typename ...> typename type_list_t, typename ...args_t>
50 struct type_list_expander<type_list_t<args_t...>>
51 {
62  template <typename fn_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 
106 template <typename unary_predicate_t, typename ...pack_t>
110 constexpr bool all_of(unary_predicate_t && fn, pack_t && ...args)
111 {
112  return (fn(std::forward<pack_t>(args)) && ...);
113 }
114 
149 template <typename type_list_t, typename unary_predicate_t>
150 [[nodiscard]] constexpr bool all_of(unary_predicate_t && fn)
152  requires type_list_specialisation<type_list_t>
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 
192 template <typename unary_function_t, typename ...pack_t>
196 constexpr void for_each(unary_function_t && fn, pack_t && ...args)
197 {
198  (fn(std::forward<pack_t>(args)), ...);
199 }
200 
235 template <typename type_list_t, typename unary_function_t>
237  requires type_list_specialisation<type_list_t>
239 constexpr 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
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.
tuple_utility.hpp
Provides utility functions for tuple like interfaces.
std::forward
T forward(T... args)
predicate
Specifies whether the given callable is std::regular_invocable and returns bool.
std::type_identity
The identity transformation (a transformation_trait that returns the input).
Definition: type_traits:31
std::invoke_result_t
invocable
Specifies whether the given callable is invocable with the given arguments.
type_list.hpp
Provides seqan3::type_list.