RESTinio
tuple_algorithms.hpp
Go to the documentation of this file.
1 /*
2  * RESTinio
3  */
4 
5 /*!
6  * @file
7  * @brief Various meta-functions for operating the content of a tuple.
8  *
9  * @since v.0.6.1
10  */
11 
12 #pragma once
13 
14 #include <restinio/compiler_features.hpp>
15 
16 #include <utility>
17 #include <tuple>
18 
19 namespace restinio
20 {
21 
22 namespace utils
23 {
24 
26 {
27 
28 namespace impl
29 {
30 
31 template< typename T >
34 
35 template< typename Predicate, typename Tuple, std::size_t... I >
36 [[nodiscard]]
37 bool
39  Predicate && p,
40  Tuple && t,
41  std::index_sequence<I...> )
42 {
43  // Use fold expression after switching to C++17.
44  return (p( std::get<I>(std::forward<Tuple>(t)) ) && ...);
45 }
46 
47 template< typename Predicate, typename Tuple, std::size_t... I >
48 [[nodiscard]]
49 bool
51  Predicate && p,
52  Tuple && t,
53  std::index_sequence<I...> )
54 {
55  // Use fold expression after switching to C++17.
56  return (p( std::get<I>(std::forward<Tuple>(t)) ) || ...);
57 }
58 
59 } /* namespace impl */
60 
61 //
62 // all_of
63 //
64 template< typename Tuple, typename Predicate >
65 [[nodiscard]]
66 bool
67 all_of( Tuple && tuple, Predicate && predicate )
68 {
69  return impl::perform_all_of(
73 }
74 
75 //
76 // any_of
77 //
78 template< typename Tuple, typename Predicate >
79 [[nodiscard]]
80 bool
81 any_of( Tuple && tuple, Predicate && predicate )
82 {
83  return impl::perform_any_of(
87 }
88 
89 } /* namespace tuple_algorithms */
90 
91 } /* namespace utils */
92 
93 } /* namespace restinio */
string_view_t from_string< string_view_t >(string_view_t s)
Get a value from string_view.
bool all_of(Tuple &&tuple, Predicate &&predicate)
bool perform_any_of(Predicate &&p, Tuple &&t, std::index_sequence< I... >)
bool any_of(Tuple &&tuple, Predicate &&predicate)
std::enable_if< std::is_same< Parameter_Container, query_string_params_t >::value||std::is_same< Parameter_Container, router::route_params_t >::value, std::optional< Value_Type > >::type opt_value(const Parameter_Container &params, string_view_t key)
Gets the value of a parameter specified by key wrapped in std::optional<Value_Type> if parameter exis...
Definition: value_or.hpp:64
bool perform_all_of(Predicate &&p, Tuple &&t, std::index_sequence< I... >)