RESTinio
tuple_algorithms.hpp
Go to the documentation of this file.
1 /*
2  * RESTinio
3  */
4 
12 #pragma once
13 
15 
16 #include <utility>
17 #include <tuple>
18 
19 namespace restinio
20 {
21 
22 namespace utils
23 {
24 
25 namespace tuple_algorithms
26 {
27 
28 namespace impl
29 {
30 
31 template< typename T >
33  std::make_index_sequence< std::tuple_size<T>::value >;
34 
35 template< typename Predicate >
37 bool
38 all_of_impl( Predicate && /*p*/ )
39 {
40  return true;
41 }
42 
43 template< typename Predicate, typename T, typename... Vs >
45 bool
46 all_of_impl( Predicate && p, T && current, Vs &&... rest )
47 {
48  return p( std::forward<T>(current) ) &&
49  all_of_impl( std::forward<Predicate>(p), std::forward<Vs>(rest)... );
50 }
51 
52 template< typename Predicate, typename Tuple, std::size_t... I >
54 bool
56  Predicate && p,
57  Tuple && t,
58  std::index_sequence<I...> )
59 {
60  return all_of_impl(
61  std::forward<Predicate>(p),
62  std::get<I>(std::forward<Tuple>(t))... );
63 }
64 
65 template< typename Predicate >
67 bool
68 any_of_impl( Predicate && /*p*/ )
69 {
70  return false;
71 }
72 
73 template< typename Predicate, typename T, typename... Vs >
75 bool
76 any_of_impl( Predicate && p, T && current, Vs &&... rest )
77 {
78  return p( std::forward<T>(current) ) ||
79  any_of_impl( std::forward<Predicate>(p), std::forward<Vs>(rest)... );
80 }
81 
82 template< typename Predicate, typename Tuple, std::size_t... I >
84 bool
86  Predicate && p,
87  Tuple && t,
88  std::index_sequence<I...> )
89 {
90  return any_of_impl(
91  std::forward<Predicate>(p),
92  std::get<I>(std::forward<Tuple>(t))... );
93 }
94 
95 } /* namespace impl */
96 
97 //
98 // all_of
99 //
100 template< typename Tuple, typename Predicate >
102 bool
103 all_of( Tuple && tuple, Predicate && predicate )
104 {
105  return impl::perform_all_of(
106  std::forward<Predicate>(predicate),
107  std::forward<Tuple>(tuple),
108  typename impl::index_sequence_for_tuple<std::decay_t<Tuple>>{} );
109 }
110 
111 //
112 // any_of
113 //
114 template< typename Tuple, typename Predicate >
116 bool
117 any_of( Tuple && tuple, Predicate && predicate )
118 {
119  return impl::perform_any_of(
120  std::forward<Predicate>(predicate),
121  std::forward<Tuple>(tuple),
122  typename impl::index_sequence_for_tuple<std::decay_t<Tuple>>{} );
123 }
124 
125 } /* namespace tuple_algorithms */
126 
127 } /* namespace utils */
128 
129 } /* namespace restinio */
130 
restinio::utils::tuple_algorithms::impl::perform_any_of
RESTINIO_NODISCARD bool perform_any_of(Predicate &&p, Tuple &&t, std::index_sequence< I... >)
Definition: tuple_algorithms.hpp:85
RESTINIO_NODISCARD
#define RESTINIO_NODISCARD
Definition: compiler_features.hpp:33
restinio::utils::tuple_algorithms::impl::index_sequence_for_tuple
std::make_index_sequence< std::tuple_size< T >::value > index_sequence_for_tuple
Definition: tuple_algorithms.hpp:33
restinio::utils::tuple_algorithms::all_of
RESTINIO_NODISCARD bool all_of(Tuple &&tuple, Predicate &&predicate)
Definition: tuple_algorithms.hpp:103
restinio::utils::tuple_algorithms::impl::perform_all_of
RESTINIO_NODISCARD bool perform_all_of(Predicate &&p, Tuple &&t, std::index_sequence< I... >)
Definition: tuple_algorithms.hpp:55
restinio::utils::tuple_algorithms::impl::any_of_impl
RESTINIO_NODISCARD bool any_of_impl(Predicate &&)
Definition: tuple_algorithms.hpp:68
restinio
Definition: asio_include.hpp:21
restinio::utils::tuple_algorithms::any_of
RESTINIO_NODISCARD bool any_of(Tuple &&tuple, Predicate &&predicate)
Definition: tuple_algorithms.hpp:117
compiler_features.hpp
Detection of compiler version and absence of various features.
restinio::utils::tuple_algorithms::impl::all_of_impl
RESTINIO_NODISCARD bool all_of_impl(Predicate &&)
Definition: tuple_algorithms.hpp:38