SeqAn3  3.1.0
The Modern C++ library for sequence analysis.
type_list_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>
16 #include <seqan3/std/type_traits>
17 #include <utility>
18 
21 
22 namespace seqan3::detail
23 {
24 
26 template <typename type_list_t>
27 struct type_list_expander;
29 
50 template <template <typename ...> typename type_list_t, typename ...args_t>
51 struct type_list_expander<type_list_t<args_t...>>
52 {
63  template <typename fn_t>
65  requires std::invocable<fn_t, std::type_identity<args_t>...>
67  static constexpr std::invoke_result_t<fn_t, std::type_identity<args_t>...> invoke_on_type_identities(fn_t && fn)
68  {
69  return fn(std::type_identity<args_t>{}...);
70  }
71 };
72 
73 //-----------------------------------------------------------------------------
74 // all_of
75 //-----------------------------------------------------------------------------
76 
111 template <typename type_list_t, typename unary_predicate_t>
112 [[nodiscard]] constexpr bool all_of(unary_predicate_t && fn)
114  requires template_specialisation_of<type_list_t, seqan3::type_list>
116 {
117  return type_list_expander<type_list_t>::invoke_on_type_identities([&] (auto && ...type_identities)
118  {
119  return all_of(fn, std::forward<decltype(type_identities)>(type_identities)...);
120  });
121 }
122 
123 //-----------------------------------------------------------------------------
124 // for_each
125 //-----------------------------------------------------------------------------
126 
161 template <typename type_list_t, typename unary_function_t>
163  requires template_specialisation_of<type_list_t, seqan3::type_list>
165 constexpr void for_each(unary_function_t && fn)
166 {
167  type_list_expander<type_list_t>::invoke_on_type_identities([&] (auto && ...type_identities)
168  {
169  for_each(fn, std::forward<decltype(type_identities)>(type_identities)...);
170  });
171 }
172 
173 } // namespace seqan3::detail
T all_of(T... args)
The <concepts> header from C++20's standard library.
T for_each(T... args)
T forward(T... args)
The identity transformation (a transformation_trait that returns the input).
Definition: type_traits:87
Provides seqan3::type_list.
Provides algorithms for meta programming, parameter packs and seqan3::type_list.
The <type_traits> header from C++20's standard library.