mirror of
https://github.com/boostorg/beast.git
synced 2025-07-30 12:57:31 +02:00
Simplify some type traits:
Several type traits are simplified and optimized to reduce compile time and memory consumption. Signed-off-by: Damian Jarek <damian.jarek93@gmail.com>
This commit is contained in:
committed by
Vinnie Falco
parent
15dd535c24
commit
65827558b8
@ -2,6 +2,7 @@ Version 191:
|
|||||||
|
|
||||||
* Add bind_front_handler
|
* Add bind_front_handler
|
||||||
* Use bind_front_handler
|
* Use bind_front_handler
|
||||||
|
* Simplify some type traits
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include <boost/beast/core/error.hpp>
|
#include <boost/beast/core/error.hpp>
|
||||||
#include <boost/asio/buffer.hpp>
|
#include <boost/asio/buffer.hpp>
|
||||||
|
#include <boost/mp11/function.hpp>
|
||||||
#include <boost/type_traits.hpp>
|
#include <boost/type_traits.hpp>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
@ -90,34 +91,6 @@ accept_rv(T){}
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
template<unsigned N, class T, class... Tn>
|
|
||||||
struct repeat_tuple_impl
|
|
||||||
{
|
|
||||||
using type = typename repeat_tuple_impl<
|
|
||||||
N - 1, T, T, Tn...>::type;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class T, class... Tn>
|
|
||||||
struct repeat_tuple_impl<0, T, Tn...>
|
|
||||||
{
|
|
||||||
using type = std::tuple<T, Tn...>;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<unsigned N, class T>
|
|
||||||
struct repeat_tuple
|
|
||||||
{
|
|
||||||
using type =
|
|
||||||
typename repeat_tuple_impl<N-1, T>::type;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
struct repeat_tuple<0, T>
|
|
||||||
{
|
|
||||||
using type = std::tuple<>;
|
|
||||||
};
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
template<class R, class C, class ...A>
|
template<class R, class C, class ...A>
|
||||||
auto
|
auto
|
||||||
is_invocable_test(C&& c, int, A&& ...a)
|
is_invocable_test(C&& c, int, A&& ...a)
|
||||||
@ -307,16 +280,9 @@ struct is_all_const_buffer_sequence<B>
|
|||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class... Bn>
|
//
|
||||||
struct common_buffers_type
|
// Returns the iterator type of a buffer sequence
|
||||||
{
|
//
|
||||||
using type = typename std::conditional<
|
|
||||||
boost::is_convertible<std::tuple<Bn...>,
|
|
||||||
typename repeat_tuple<sizeof...(Bn),
|
|
||||||
boost::asio::mutable_buffer>::type>::value,
|
|
||||||
boost::asio::mutable_buffer,
|
|
||||||
boost::asio::const_buffer>::type;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class B>
|
template<class B>
|
||||||
struct buffer_sequence_iterator
|
struct buffer_sequence_iterator
|
||||||
@ -326,6 +292,60 @@ struct buffer_sequence_iterator
|
|||||||
std::declval<B const&>()));
|
std::declval<B const&>()));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct buffer_sequence_iterator<
|
||||||
|
boost::asio::const_buffer>
|
||||||
|
{
|
||||||
|
using type = boost::asio::const_buffer const*;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct buffer_sequence_iterator<
|
||||||
|
boost::asio::mutable_buffer>
|
||||||
|
{
|
||||||
|
using type = boost::asio::mutable_buffer const*;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Returns the value type of the iterator of a buffer sequence
|
||||||
|
//
|
||||||
|
|
||||||
|
template<class B>
|
||||||
|
struct buffer_sequence_value_type
|
||||||
|
{
|
||||||
|
using type = typename std::iterator_traits<
|
||||||
|
typename buffer_sequence_iterator<B>::type
|
||||||
|
>::value_type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct buffer_sequence_value_type<
|
||||||
|
boost::asio::const_buffer const*>
|
||||||
|
{
|
||||||
|
using type = boost::asio::const_buffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct buffer_sequence_value_type<
|
||||||
|
boost::asio::mutable_buffer const*>
|
||||||
|
{
|
||||||
|
using type = boost::asio::mutable_buffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
template<class... Bn>
|
||||||
|
struct common_buffers_type
|
||||||
|
{
|
||||||
|
using type = typename std::conditional<
|
||||||
|
mp11::mp_and<
|
||||||
|
boost::is_convertible<
|
||||||
|
typename buffer_sequence_value_type<Bn>::type,
|
||||||
|
boost::asio::mutable_buffer>...>::value,
|
||||||
|
boost::asio::mutable_buffer,
|
||||||
|
boost::asio::const_buffer>::type;
|
||||||
|
};
|
||||||
|
|
||||||
// Types that meet the requirements,
|
// Types that meet the requirements,
|
||||||
// for use with std::declval only.
|
// for use with std::declval only.
|
||||||
struct StreamHandler
|
struct StreamHandler
|
||||||
|
@ -224,7 +224,7 @@ public:
|
|||||||
using boost::beast::buffers_suffix;
|
using boost::beast::buffers_suffix;
|
||||||
using boost::asio::buffer;
|
using boost::asio::buffer;
|
||||||
using boost::asio::const_buffer;
|
using boost::asio::const_buffer;
|
||||||
|
|
||||||
char out[64];
|
char out[64];
|
||||||
std::array<const_buffer, 2> buffers{
|
std::array<const_buffer, 2> buffers{
|
||||||
{buffer("Hello, "), buffer("world!")}};
|
{buffer("Hello, "), buffer("world!")}};
|
||||||
@ -283,8 +283,8 @@ public:
|
|||||||
mutable_buffer,
|
mutable_buffer,
|
||||||
decltype(buffers_cat(
|
decltype(buffers_cat(
|
||||||
std::declval<mutable_buffer>(),
|
std::declval<mutable_buffer>(),
|
||||||
std::declval<user_defined>(),
|
std::declval<mutable_buffer>(),
|
||||||
std::declval<mutable_buffer>()
|
std::declval<std::vector<mutable_buffer>>()
|
||||||
))::value_type>::value);
|
))::value_type>::value);
|
||||||
|
|
||||||
// Ensure that concatenating mixed buffer
|
// Ensure that concatenating mixed buffer
|
||||||
|
Reference in New Issue
Block a user