tuple_algorithms.hpp
Go to the documentation of this file.
/*
* RESTinio
*/
#pragma once
#include <restinio/compiler_features.hpp>
#include <utility>
#include <tuple>
namespace restinio
{
namespace utils
{
namespace tuple_algorithms
{
namespace impl
{
template< typename T >
using index_sequence_for_tuple =
std::make_index_sequence< std::tuple_size<T>::value >;
template< typename Predicate >
RESTINIO_NODISCARD
bool
all_of_impl( Predicate && /*p*/ )
{
return true;
}
template< typename Predicate, typename T, typename... Vs >
RESTINIO_NODISCARD
bool
all_of_impl( Predicate && p, T && current, Vs &&... rest )
{
return p( std::forward<T>(current) ) &&
all_of_impl( std::forward<Predicate>(p), std::forward<Vs>(rest)... );
}
template< typename Predicate, typename Tuple, std::size_t... I >
RESTINIO_NODISCARD
bool
perform_all_of(
Predicate && p,
Tuple && t,
std::index_sequence<I...> )
{
return all_of_impl(
std::forward<Predicate>(p),
std::get<I>(std::forward<Tuple>(t))... );
}
template< typename Predicate >
RESTINIO_NODISCARD
bool
any_of_impl( Predicate && /*p*/ )
{
return false;
}
template< typename Predicate, typename T, typename... Vs >
RESTINIO_NODISCARD
bool
any_of_impl( Predicate && p, T && current, Vs &&... rest )
{
return p( std::forward<T>(current) ) ||
any_of_impl( std::forward<Predicate>(p), std::forward<Vs>(rest)... );
}
template< typename Predicate, typename Tuple, std::size_t... I >
RESTINIO_NODISCARD
bool
perform_any_of(
Predicate && p,
Tuple && t,
std::index_sequence<I...> )
{
return any_of_impl(
std::forward<Predicate>(p),
std::get<I>(std::forward<Tuple>(t))... );
}
} /* namespace impl */
//
// all_of
//
template< typename Tuple, typename Predicate >
RESTINIO_NODISCARD
bool
all_of( Tuple && tuple, Predicate && predicate )
{
return impl::perform_all_of(
std::forward<Predicate>(predicate),
std::forward<Tuple>(tuple),
typename impl::index_sequence_for_tuple<std::decay_t<Tuple>>{} );
}
//
// any_of
//
template< typename Tuple, typename Predicate >
RESTINIO_NODISCARD
bool
any_of( Tuple && tuple, Predicate && predicate )
{
return impl::perform_any_of(
std::forward<Predicate>(predicate),
std::forward<Tuple>(tuple),
typename impl::index_sequence_for_tuple<std::decay_t<Tuple>>{} );
}
} /* namespace tuple_algorithms */
} /* namespace utils */
} /* namespace restinio */
compiler_features.hpp
Detection of compiler version and absence of various features.
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::impl::perform_any_of
RESTINIO_NODISCARD bool perform_any_of(Predicate &&p, Tuple &&t, std::index_sequence< I... >)
Definition: tuple_algorithms.hpp:85
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::all_of_impl
RESTINIO_NODISCARD bool all_of_impl(Predicate &&)
Definition: tuple_algorithms.hpp:38
restinio::utils::tuple_algorithms::impl::any_of_impl
RESTINIO_NODISCARD bool any_of_impl(Predicate &&)
Definition: tuple_algorithms.hpp:68
restinio::utils::tuple_algorithms::all_of
RESTINIO_NODISCARD bool all_of(Tuple &&tuple, Predicate &&predicate)
Definition: tuple_algorithms.hpp:103
restinio::utils::tuple_algorithms::any_of
RESTINIO_NODISCARD bool any_of(Tuple &&tuple, Predicate &&predicate)
Definition: tuple_algorithms.hpp:117
restinio
Definition: asio_include.hpp:21