123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- #ifndef ASIO_USE_AWAITABLE_HPP
- #define ASIO_USE_AWAITABLE_HPP
- #if defined(_MSC_VER) && (_MSC_VER >= 1200)
- # pragma once
- #endif
- #include "asio/detail/config.hpp"
- #if defined(ASIO_HAS_CO_AWAIT) || defined(GENERATING_DOCUMENTATION)
- #include "asio/awaitable.hpp"
- #include "asio/detail/handler_tracking.hpp"
- #if defined(ASIO_ENABLE_HANDLER_TRACKING)
- # if defined(ASIO_HAS_SOURCE_LOCATION)
- # include "asio/detail/source_location.hpp"
- # endif
- #endif
- #include "asio/detail/push_options.hpp"
- namespace asio {
- template <typename Executor = any_io_executor>
- struct use_awaitable_t
- {
-
- constexpr use_awaitable_t(
- #if defined(ASIO_ENABLE_HANDLER_TRACKING)
- # if defined(ASIO_HAS_SOURCE_LOCATION)
- detail::source_location location = detail::source_location::current()
- # endif
- #endif
- )
- #if defined(ASIO_ENABLE_HANDLER_TRACKING)
- # if defined(ASIO_HAS_SOURCE_LOCATION)
- : file_name_(location.file_name()),
- line_(location.line()),
- function_name_(location.function_name())
- # else
- : file_name_(0),
- line_(0),
- function_name_(0)
- # endif
- #endif
- {
- }
-
- constexpr use_awaitable_t(const char* file_name,
- int line, const char* function_name)
- #if defined(ASIO_ENABLE_HANDLER_TRACKING)
- : file_name_(file_name),
- line_(line),
- function_name_(function_name)
- #endif
- {
- #if !defined(ASIO_ENABLE_HANDLER_TRACKING)
- (void)file_name;
- (void)line;
- (void)function_name;
- #endif
- }
-
-
- template <typename InnerExecutor>
- struct executor_with_default : InnerExecutor
- {
-
- typedef use_awaitable_t default_completion_token_type;
-
- template <typename InnerExecutor1>
- executor_with_default(const InnerExecutor1& ex,
- constraint_t<
- conditional_t<
- !is_same<InnerExecutor1, executor_with_default>::value,
- is_convertible<InnerExecutor1, InnerExecutor>,
- false_type
- >::value
- > = 0) noexcept
- : InnerExecutor(ex)
- {
- }
- };
-
-
- template <typename T>
- using as_default_on_t = typename T::template rebind_executor<
- executor_with_default<typename T::executor_type>>::other;
-
-
- template <typename T>
- static typename decay_t<T>::template rebind_executor<
- executor_with_default<typename decay_t<T>::executor_type>
- >::other
- as_default_on(T&& object)
- {
- return typename decay_t<T>::template rebind_executor<
- executor_with_default<typename decay_t<T>::executor_type>
- >::other(static_cast<T&&>(object));
- }
- #if defined(ASIO_ENABLE_HANDLER_TRACKING)
- const char* file_name_;
- int line_;
- const char* function_name_;
- #endif
- };
- #if defined(GENERATING_DOCUMENTATION)
- constexpr use_awaitable_t<> use_awaitable;
- #else
- constexpr use_awaitable_t<> use_awaitable(0, 0, 0);
- #endif
- }
- #include "asio/detail/pop_options.hpp"
- #include "asio/impl/use_awaitable.hpp"
- #endif
- #endif
|