File indexing completed on 2025-01-18 09:29:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_BEAST_DETAIL_REMAP_POST_TO_DEFER_HPP
0011 #define BOOST_BEAST_DETAIL_REMAP_POST_TO_DEFER_HPP
0012
0013 #include <boost/asio/is_executor.hpp>
0014 #include <boost/core/empty_value.hpp>
0015 #include <type_traits>
0016 #include <utility>
0017
0018 namespace boost {
0019 namespace beast {
0020 namespace detail {
0021
0022 template<class Executor>
0023 class remap_post_to_defer
0024 : private boost::empty_value<Executor>
0025 {
0026 BOOST_STATIC_ASSERT(
0027 net::is_executor<Executor>::value);
0028
0029 Executor const&
0030 ex() const noexcept
0031 {
0032 return this->get();
0033 }
0034
0035 public:
0036 remap_post_to_defer(
0037 remap_post_to_defer&&) = default;
0038
0039 remap_post_to_defer(
0040 remap_post_to_defer const&) = default;
0041
0042 explicit
0043 remap_post_to_defer(
0044 Executor const& ex)
0045 : boost::empty_value<Executor>(
0046 boost::empty_init_t{}, ex)
0047 {
0048 }
0049
0050 bool
0051 operator==(
0052 remap_post_to_defer const& other) const noexcept
0053 {
0054 return ex() == other.ex();
0055 }
0056
0057 bool
0058 operator!=(
0059 remap_post_to_defer const& other) const noexcept
0060 {
0061 return ex() != other.ex();
0062 }
0063
0064 decltype(std::declval<Executor const&>().context())
0065 context() const noexcept
0066 {
0067 return ex().context();
0068 }
0069
0070 void
0071 on_work_started() const noexcept
0072 {
0073 ex().on_work_started();
0074 }
0075
0076 void
0077 on_work_finished() const noexcept
0078 {
0079 ex().on_work_finished();
0080 }
0081
0082 template<class F, class A>
0083 void
0084 dispatch(F&& f, A const& a) const
0085 {
0086 ex().dispatch(std::forward<F>(f), a);
0087 }
0088
0089 template<class F, class A>
0090 void
0091 post(F&& f, A const& a) const
0092 {
0093 ex().defer(std::forward<F>(f), a);
0094 }
0095
0096 template<class F, class A>
0097 void
0098 defer(F&& f, A const& a) const
0099 {
0100 ex().defer(std::forward<F>(f), a);
0101 }
0102 };
0103
0104 }
0105 }
0106 }
0107
0108 #endif