File indexing completed on 2025-12-16 09:43:32
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_ASSOCIATED_CANCELLATION_SLOT_HPP
0012 #define BOOST_ASIO_ASSOCIATED_CANCELLATION_SLOT_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019 #include <boost/asio/associator.hpp>
0020 #include <boost/asio/cancellation_signal.hpp>
0021 #include <boost/asio/detail/functional.hpp>
0022 #include <boost/asio/detail/type_traits.hpp>
0023
0024 #include <boost/asio/detail/push_options.hpp>
0025
0026 namespace boost {
0027 namespace asio {
0028
0029 template <typename T, typename CancellationSlot>
0030 struct associated_cancellation_slot;
0031
0032 namespace detail {
0033
0034 template <typename T, typename = void>
0035 struct has_cancellation_slot_type : false_type
0036 {
0037 };
0038
0039 template <typename T>
0040 struct has_cancellation_slot_type<T, void_t<typename T::cancellation_slot_type>>
0041 : true_type
0042 {
0043 };
0044
0045 template <typename T, typename S, typename = void, typename = void>
0046 struct associated_cancellation_slot_impl
0047 {
0048 typedef void asio_associated_cancellation_slot_is_unspecialised;
0049
0050 typedef S type;
0051
0052 static type get(const T&) noexcept
0053 {
0054 return type();
0055 }
0056
0057 static const type& get(const T&, const S& s) noexcept
0058 {
0059 return s;
0060 }
0061 };
0062
0063 template <typename T, typename S>
0064 struct associated_cancellation_slot_impl<T, S,
0065 void_t<typename T::cancellation_slot_type>>
0066 {
0067 typedef typename T::cancellation_slot_type type;
0068
0069 static auto get(const T& t) noexcept
0070 -> decltype(t.get_cancellation_slot())
0071 {
0072 return t.get_cancellation_slot();
0073 }
0074
0075 static auto get(const T& t, const S&) noexcept
0076 -> decltype(t.get_cancellation_slot())
0077 {
0078 return t.get_cancellation_slot();
0079 }
0080 };
0081
0082 template <typename T, typename S>
0083 struct associated_cancellation_slot_impl<T, S,
0084 enable_if_t<
0085 !has_cancellation_slot_type<T>::value
0086 >,
0087 void_t<
0088 typename associator<associated_cancellation_slot, T, S>::type
0089 >> : associator<associated_cancellation_slot, T, S>
0090 {
0091 };
0092
0093 }
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116 template <typename T, typename CancellationSlot = cancellation_slot>
0117 struct associated_cancellation_slot
0118 #if !defined(GENERATING_DOCUMENTATION)
0119 : detail::associated_cancellation_slot_impl<T, CancellationSlot>
0120 #endif
0121 {
0122 #if defined(GENERATING_DOCUMENTATION)
0123
0124
0125
0126 typedef see_below type;
0127
0128
0129
0130 static decltype(auto) get(const T& t) noexcept;
0131
0132
0133
0134 static decltype(auto) get(const T& t,
0135 const CancellationSlot& s) noexcept;
0136 #endif
0137 };
0138
0139
0140
0141
0142
0143 template <typename T>
0144 BOOST_ASIO_NODISCARD inline typename associated_cancellation_slot<T>::type
0145 get_associated_cancellation_slot(const T& t) noexcept
0146 {
0147 return associated_cancellation_slot<T>::get(t);
0148 }
0149
0150
0151
0152
0153
0154
0155 template <typename T, typename CancellationSlot>
0156 BOOST_ASIO_NODISCARD inline auto get_associated_cancellation_slot(
0157 const T& t, const CancellationSlot& st) noexcept
0158 -> decltype(associated_cancellation_slot<T, CancellationSlot>::get(t, st))
0159 {
0160 return associated_cancellation_slot<T, CancellationSlot>::get(t, st);
0161 }
0162
0163 template <typename T, typename CancellationSlot = cancellation_slot>
0164 using associated_cancellation_slot_t =
0165 typename associated_cancellation_slot<T, CancellationSlot>::type;
0166
0167 namespace detail {
0168
0169 template <typename T, typename S, typename = void>
0170 struct associated_cancellation_slot_forwarding_base
0171 {
0172 };
0173
0174 template <typename T, typename S>
0175 struct associated_cancellation_slot_forwarding_base<T, S,
0176 enable_if_t<
0177 is_same<
0178 typename associated_cancellation_slot<T,
0179 S>::asio_associated_cancellation_slot_is_unspecialised,
0180 void
0181 >::value
0182 >>
0183 {
0184 typedef void asio_associated_cancellation_slot_is_unspecialised;
0185 };
0186
0187 }
0188
0189
0190
0191 template <typename T, typename CancellationSlot>
0192 struct associated_cancellation_slot<reference_wrapper<T>, CancellationSlot>
0193 #if !defined(GENERATING_DOCUMENTATION)
0194 : detail::associated_cancellation_slot_forwarding_base<T, CancellationSlot>
0195 #endif
0196 {
0197
0198
0199 typedef typename associated_cancellation_slot<T, CancellationSlot>::type type;
0200
0201
0202
0203 static type get(reference_wrapper<T> t) noexcept
0204 {
0205 return associated_cancellation_slot<T, CancellationSlot>::get(t.get());
0206 }
0207
0208
0209
0210 static auto get(reference_wrapper<T> t, const CancellationSlot& s) noexcept
0211 -> decltype(
0212 associated_cancellation_slot<T, CancellationSlot>::get(t.get(), s))
0213 {
0214 return associated_cancellation_slot<T, CancellationSlot>::get(t.get(), s);
0215 }
0216 };
0217
0218 }
0219 }
0220
0221 #include <boost/asio/detail/pop_options.hpp>
0222
0223 #endif