metaprogramming.hpp
Go to the documentation of this file.
/*
* RESTinio
*/
#pragma once
#include <type_traits>
namespace restinio
{
namespace utils
{
namespace metaprogramming
{
// See https://en.cppreference.com/w/cpp/types/void_t for details.
template<typename... Ts> struct make_void { using type = void; };
template<typename... Ts> using void_t = typename make_void<Ts...>::type;
namespace impl
{
//
// debug_print
//
/*
* NOTE: this type is intended to be used just for debugging
* metaprogramming stuff. That is why it hasn't the definition.
*/
template<typename T>
struct debug_print;
} /* namespace impl */
//
// type_list
//
template<typename... Types>
struct type_list {};
namespace impl
{
//
// head_of
//
template<typename T, typename... Rest>
struct head_of
{
using type = T;
};
template<typename T>
struct head_of<T>
{
using type = T;
};
} /* namespace impl */
//
// head_of_t
//
template<typename... L>
using head_of_t = typename impl::head_of<L...>::type;
namespace impl
{
//
// tail_of
//
template<typename T, typename... Rest>
struct tail_of
{
using type = type_list<Rest...>;
};
template<typename L>
struct tail_of<L>
{
using type = type_list<>;
};
} /* namespace impl */
template<typename... L>
using tail_of_t = typename impl::tail_of<L...>::type;
namespace impl
{
//
// put_front
//
template<typename T, typename Rest>
struct put_front;
template<typename T, template<class...> class L, typename... Rest>
struct put_front< T, L<Rest...> >
{
using type = L<T, Rest...>;
};
} /* namespace impl */
//
// put_front_t
//
template<typename T, typename Rest>
using put_front_t = typename impl::put_front<T, Rest>::type;
namespace impl
{
//
// rename
//
template<typename From, template<class...> class To>
struct rename;
template<
template<class...> class From,
typename... Types,
template<class...> class To>
struct rename<From<Types...>, To>
{
using type = To<Types...>;
};
} /* namespace impl */
//
// rename_t
//
template<typename From, template<class...> class To>
using rename_t = typename impl::rename<From, To>::type;
namespace impl
{
//
// transform
//
template<
template<class...> class Transform_F,
typename To,
typename From >
struct transform;
template<
template<class...> class Transform_F,
template<class...> class From,
typename... Sources,
template<class...> class To,
typename... Results >
struct transform< Transform_F, From<Sources...>, To<Results...> >
{
using type = typename transform<
Transform_F,
tail_of_t<Sources...>,
To<Results..., typename Transform_F< head_of_t<Sources...> >::type>
>::type;
};
template<
template<class...> class Transform_F,
template<class...> class From,
template<class...> class To,
typename... Results >
struct transform< Transform_F, From<>, To<Results...> >
{
using type = To<Results...>;
};
} /* namespace impl */
template< template<class...> class Transform_F, typename From >
using transform_t = typename impl::transform<
Transform_F,
From,
type_list<>
>::type;
namespace impl
{
//
// all_of
//
template<
template<class...> class Predicate,
typename H,
typename... Tail >
struct all_of
{
static constexpr bool value = Predicate<H>::value &&
all_of<Predicate, Tail...>::value;
};
template<
template<class...> class Predicate,
typename H >
struct all_of< Predicate, H >
{
static constexpr bool value = Predicate<H>::value;
};
// Specialization for the case when types are represented as type_list.
//
// Since v.0.6.6.
template<
template<class...> class Predicate,
typename... Types >
struct all_of< Predicate, type_list<Types...> >
{
static constexpr bool value = all_of<Predicate, Types...>::value;
};
} /* namespace impl */
//
// all_of
//
template< template<class...> class Predicate, typename... List >
constexpr bool all_of_v = impl::all_of<Predicate, List...>::value;
} /* namespace metaprogramming */
} /* namespace utils */
} /* namespace restinio */
restinio::utils::metaprogramming::tail_of_t
typename impl::tail_of< L... >::type tail_of_t
Metafunction to get the tail of a list of types in a form of type_list.
Definition: metaprogramming.hpp:129
restinio::utils::metaprogramming::put_front_t
typename impl::put_front< T, Rest >::type put_front_t
Metafunction to insert a type to the front of a type_list.
Definition: metaprogramming.hpp:165
restinio::utils::metaprogramming::all_of_v
constexpr bool all_of_v
Applies the predicate to all types from the list and return true only if all types satisty that predi...
Definition: metaprogramming.hpp:325
restinio::utils::metaprogramming::rename_t
typename impl::rename< From, To >::type rename_t
Allows to pass all template arguments from one type to another.
Definition: metaprogramming.hpp:203
restinio::utils::metaprogramming::head_of_t
typename impl::head_of< L... >::type head_of_t
Metafunction to get the first item from a list of types.
Definition: metaprogramming.hpp:91
restinio::utils::metaprogramming::void_t
typename make_void< Ts... >::type void_t
Definition: metaprogramming.hpp:28
restinio::utils::metaprogramming::transform_t
typename impl::transform< Transform_F, From, type_list<> >::type transform_t
Applies a specified meta-function to every item from a specified type-list and return a new type-list...
Definition: metaprogramming.hpp:263
restinio
Definition: asio_include.hpp:21
restinio::utils::metaprogramming::impl::all_of
Definition: metaprogramming.hpp:276
restinio::utils::metaprogramming::impl::all_of::value
static constexpr bool value
Definition: metaprogramming.hpp:277
restinio::utils::metaprogramming::impl::debug_print
Definition: metaprogramming.hpp:41
restinio::utils::metaprogramming::impl::head_of< T >::type
T type
Definition: metaprogramming.hpp:71
restinio::utils::metaprogramming::impl::head_of
Definition: metaprogramming.hpp:64
restinio::utils::metaprogramming::impl::head_of::type
T type
Definition: metaprogramming.hpp:65
restinio::utils::metaprogramming::impl::put_front< T, L< Rest... > >::type
L< T, Rest... > type
Definition: metaprogramming.hpp:143
restinio::utils::metaprogramming::impl::put_front
Definition: metaprogramming.hpp:138
restinio::utils::metaprogramming::impl::rename< From< Types... >, To >::type
To< Types... > type
Definition: metaprogramming.hpp:182
restinio::utils::metaprogramming::impl::rename
Definition: metaprogramming.hpp:174
restinio::utils::metaprogramming::impl::tail_of
Definition: metaprogramming.hpp:101
restinio::utils::metaprogramming::impl::transform< Transform_F, From<>, To< Results... > >::type
To< Results... > type
Definition: metaprogramming.hpp:240
restinio::utils::metaprogramming::impl::transform< Transform_F, From< Sources... >, To< Results... > >::type
typename transform< Transform_F, tail_of_t< Sources... >, To< Results..., typename Transform_F< head_of_t< Sources... > >::type > >::type type
Definition: metaprogramming.hpp:230
restinio::utils::metaprogramming::impl::transform
Definition: metaprogramming.hpp:216
restinio::utils::metaprogramming::make_void
Definition: metaprogramming.hpp:27
restinio::utils::metaprogramming::make_void::type
void type
Definition: metaprogramming.hpp:27
restinio::utils::metaprogramming::type_list
The basic building block: a type for representation of a type list.
Definition: metaprogramming.hpp:54