Warning, file /include/boost/asio/disposition.hpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_DISPOSITION_HPP
0012 #define BOOST_ASIO_DISPOSITION_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/detail/throw_exception.hpp>
0020 #include <boost/asio/detail/type_traits.hpp>
0021 #include <boost/system/error_code.hpp>
0022 #include <boost/system/system_error.hpp>
0023 #include <exception>
0024
0025 #include <boost/asio/detail/push_options.hpp>
0026
0027 namespace boost {
0028 namespace asio {
0029
0030
0031
0032
0033
0034
0035
0036
0037 #if defined(GENERATING_DOCUMENTATION)
0038 template <typename T>
0039 struct disposition_traits
0040 {
0041
0042 static bool not_an_error(const T& d) noexcept;
0043
0044
0045 static void throw_exception(T d);
0046
0047
0048 static std::exception_ptr to_exception_ptr(T d) noexcept;
0049 };
0050 #else
0051 template <typename T>
0052 struct disposition_traits;
0053 #endif
0054
0055 namespace detail {
0056
0057 template <typename T, typename = void, typename = void,
0058 typename = void, typename = void, typename = void, typename = void>
0059 struct is_disposition_impl : false_type
0060 {
0061 };
0062
0063 template <typename T>
0064 struct is_disposition_impl<T,
0065 enable_if_t<
0066 is_nothrow_default_constructible<T>::value
0067 >,
0068 enable_if_t<
0069 is_nothrow_move_constructible<T>::value
0070 >,
0071 enable_if_t<
0072 is_nothrow_move_assignable<T>::value
0073 >,
0074 enable_if_t<
0075 is_same<
0076 decltype(disposition_traits<T>::not_an_error(declval<const T&>())),
0077 bool
0078 >::value
0079 >,
0080 void_t<
0081 decltype(disposition_traits<T>::throw_exception(declval<T>()))
0082 >,
0083 enable_if_t<
0084 is_same<
0085 decltype(disposition_traits<T>::to_exception_ptr(declval<T>())),
0086 std::exception_ptr
0087 >::value
0088 >> : true_type
0089 {
0090 };
0091
0092 }
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109 template <typename T>
0110 struct is_disposition :
0111 #if defined(GENERATING_DOCUMENTATION)
0112 integral_constant<bool, automatically_determined>
0113 #else
0114 detail::is_disposition_impl<T>
0115 #endif
0116 {
0117 };
0118
0119 #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
0120
0121 template <typename T>
0122 constexpr const bool is_disposition_v = is_disposition<T>::value;
0123
0124 #endif
0125
0126 #if defined(BOOST_ASIO_HAS_CONCEPTS)
0127
0128 template <typename T>
0129 BOOST_ASIO_CONCEPT disposition = is_disposition<T>::value;
0130
0131 #define BOOST_ASIO_DISPOSITION ::boost::asio::disposition
0132
0133 #else
0134
0135 #define BOOST_ASIO_DISPOSITION typename
0136
0137 #endif
0138
0139
0140 template <>
0141 struct disposition_traits<boost::system::error_code>
0142 {
0143 static bool not_an_error(const boost::system::error_code& ec) noexcept
0144 {
0145 return !ec;
0146 }
0147
0148 static void throw_exception(const boost::system::error_code& ec)
0149 {
0150 detail::throw_exception(boost::system::system_error(ec));
0151 }
0152
0153 static std::exception_ptr to_exception_ptr(
0154 const boost::system::error_code& ec) noexcept
0155 {
0156 return ec
0157 ? std::make_exception_ptr(boost::system::system_error(ec))
0158 : nullptr;
0159 }
0160 };
0161
0162
0163 template <>
0164 struct disposition_traits<std::exception_ptr>
0165 {
0166 static bool not_an_error(const std::exception_ptr& e) noexcept
0167 {
0168 return !e;
0169 }
0170
0171 static void throw_exception(std::exception_ptr e)
0172 {
0173 std::rethrow_exception(static_cast<std::exception_ptr&&>(e));
0174 }
0175
0176 static std::exception_ptr to_exception_ptr(std::exception_ptr e) noexcept
0177 {
0178 return e;
0179 }
0180 };
0181
0182
0183 struct no_error_t
0184 {
0185
0186 constexpr no_error_t()
0187 {
0188 }
0189
0190
0191 friend constexpr bool operator==(
0192 const no_error_t&, const no_error_t&) noexcept
0193 {
0194 return true;
0195 }
0196
0197
0198 friend constexpr bool operator!=(
0199 const no_error_t&, const no_error_t&) noexcept
0200 {
0201 return false;
0202 }
0203
0204
0205
0206 template <BOOST_ASIO_DISPOSITION Disposition>
0207 friend constexpr constraint_t<is_disposition<Disposition>::value, bool>
0208 operator==(const no_error_t&, const Disposition& d) noexcept
0209 {
0210 return disposition_traits<Disposition>::not_an_error(d);
0211 }
0212
0213
0214
0215 template <BOOST_ASIO_DISPOSITION Disposition>
0216 friend constexpr constraint_t<is_disposition<Disposition>::value, bool>
0217 operator==(const Disposition& d, const no_error_t&) noexcept
0218 {
0219 return disposition_traits<Disposition>::not_an_error(d);
0220 }
0221
0222
0223 template <BOOST_ASIO_DISPOSITION Disposition>
0224 friend constexpr constraint_t<is_disposition<Disposition>::value, bool>
0225 operator!=(const no_error_t&, const Disposition& d) noexcept
0226 {
0227 return !disposition_traits<Disposition>::not_an_error(d);
0228 }
0229
0230
0231 template <BOOST_ASIO_DISPOSITION Disposition>
0232 friend constexpr constraint_t<is_disposition<Disposition>::value, bool>
0233 operator!=(const Disposition& d, const no_error_t&) noexcept
0234 {
0235 return !disposition_traits<Disposition>::not_an_error(d);
0236 }
0237 };
0238
0239
0240 BOOST_ASIO_INLINE_VARIABLE constexpr no_error_t no_error;
0241
0242
0243 template <>
0244 struct disposition_traits<no_error_t>
0245 {
0246 static bool not_an_error(no_error_t) noexcept
0247 {
0248 return true;
0249 }
0250
0251 static void throw_exception(no_error_t)
0252 {
0253 }
0254
0255 static std::exception_ptr to_exception_ptr(no_error_t) noexcept
0256 {
0257 return std::exception_ptr();
0258 }
0259 };
0260
0261
0262 template <typename Disposition>
0263 inline void throw_exception(Disposition&& d,
0264 constraint_t<is_disposition<decay_t<Disposition>>::value> = 0)
0265 {
0266 disposition_traits<decay_t<Disposition>>::throw_exception(
0267 static_cast<Disposition&&>(d));
0268 }
0269
0270
0271 template <typename Disposition>
0272 inline std::exception_ptr to_exception_ptr(Disposition&& d,
0273 constraint_t<is_disposition<decay_t<Disposition>>::value> = 0) noexcept
0274 {
0275 return disposition_traits<decay_t<Disposition>>::to_exception_ptr(
0276 static_cast<Disposition&&>(d));
0277 }
0278
0279 }
0280 }
0281
0282 #include <boost/asio/detail/pop_options.hpp>
0283
0284 #endif