1//
2// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
3//
4// Distributed under the Boost Software License, Version 1.0. (See accompanying
5// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6//
7// Official repository: https://github.com/boostorg/beast
8//
9
10#ifndef BOOST_BEAST_DETAIL_STREAM_TRAITS_HPP
11#define BOOST_BEAST_DETAIL_STREAM_TRAITS_HPP
12
13#include <boost/beast/core/error.hpp>
14#include <boost/asio/buffer.hpp>
15#include <boost/type_traits/make_void.hpp>
16#include <type_traits>
17
18namespace boost {
19namespace beast {
20namespace detail {
21
22//------------------------------------------------------------------------------
23//
24// get_lowest_layer
25// lowest_layer_type
26// detail::has_next_layer
27//
28
29template <class T>
30std::false_type has_next_layer_impl(void*);
31
32template <class T>
33auto has_next_layer_impl(decltype(nullptr)) ->
34 decltype(std::declval<T&>().next_layer(), std::true_type{});
35
36template <class T>
37using has_next_layer = decltype(has_next_layer_impl<T>(nullptr));
38
39template<class T, bool = has_next_layer<T>::value>
40struct lowest_layer_type_impl
41{
42 using type = typename std::remove_reference<T>::type;
43};
44
45template<class T>
46struct lowest_layer_type_impl<T, true>
47{
48 using type = typename lowest_layer_type_impl<
49 decltype(std::declval<T&>().next_layer())>::type;
50};
51
52template<class T>
53using lowest_layer_type = typename
54 lowest_layer_type_impl<T>::type;
55
56template<class T>
57T&
58get_lowest_layer_impl(
59 T& t, std::false_type) noexcept
60{
61 return t;
62}
63
64template<class T>
65lowest_layer_type<T>&
66get_lowest_layer_impl(
67 T& t, std::true_type) noexcept
68{
69 return get_lowest_layer_impl(t.next_layer(),
70 has_next_layer<typename std::decay<
71 decltype(t.next_layer())>::type>{});
72}
73
74//------------------------------------------------------------------------------
75
76// Types that meet the requirements,
77// for use with std::declval only.
78template<class BufferType>
79struct BufferSequence
80{
81 using value_type = BufferType;
82 using const_iterator = BufferType const*;
83 ~BufferSequence() = default;
84 BufferSequence(BufferSequence const&) = default;
85 const_iterator begin() const noexcept { return {}; }
86 const_iterator end() const noexcept { return {}; }
87};
88using ConstBufferSequence =
89 BufferSequence<net::const_buffer>;
90using MutableBufferSequence =
91 BufferSequence<net::mutable_buffer>;
92
93//
94
95// Types that meet the requirements,
96// for use with std::declval only.
97struct StreamHandler
98{
99 StreamHandler(StreamHandler const&) = default;
100 void operator()(error_code, std::size_t) {}
101};
102using ReadHandler = StreamHandler;
103using WriteHandler = StreamHandler;
104
105//------------------------------------------------------------------------------
106
107} // detail
108} // beast
109} // boost
110
111#endif
112

source code of boost/libs/beast/include/boost/beast/core/detail/stream_traits.hpp