RESTinio
Loading...
Searching...
No Matches
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
19namespace restinio
20{
21
22namespace utils
23{
24
25namespace tuple_algorithms
26{
27
28namespace impl
29{
30
31template< typename T >
33 std::make_index_sequence< std::tuple_size<T>::value >;
34
35template< typename Predicate, typename Tuple, std::size_t... I >
36[[nodiscard]]
37bool
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
47template< typename Predicate, typename Tuple, std::size_t... I >
48[[nodiscard]]
49bool
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//
64template< typename Tuple, typename Predicate >
65[[nodiscard]]
66bool
67all_of( Tuple && tuple, Predicate && predicate )
68{
70 std::forward<Predicate>(predicate),
71 std::forward<Tuple>(tuple),
72 typename impl::index_sequence_for_tuple<std::decay_t<Tuple>>{} );
73}
74
75//
76// any_of
77//
78template< typename Tuple, typename Predicate >
79[[nodiscard]]
80bool
81any_of( Tuple && tuple, Predicate && predicate )
82{
84 std::forward<Predicate>(predicate),
85 std::forward<Tuple>(tuple),
86 typename impl::index_sequence_for_tuple<std::decay_t<Tuple>>{} );
87}
88
89} /* namespace tuple_algorithms */
90
91} /* namespace utils */
92
93} /* namespace restinio */
94
Detection of compiler version and absence of various features.
bool perform_all_of(Predicate &&p, Tuple &&t, std::index_sequence< I... >)
bool perform_any_of(Predicate &&p, Tuple &&t, std::index_sequence< I... >)
std::make_index_sequence< std::tuple_size< T >::value > index_sequence_for_tuple
bool all_of(Tuple &&tuple, Predicate &&predicate)
bool any_of(Tuple &&tuple, Predicate &&predicate)
run_on_this_thread_settings_t< Traits > on_this_thread()
A special marker for the case when http_server must be run on the context of the current thread.